Reputation: 3223
The following code is producing a wrong conversion of a Timestamp (1350553368
):
$dateTime = new DateTime();
$dateTime->setTimeStamp(1350553368);
echo $dateTime->format('F n, Y');
PHP converts it to October 10, 2012: http://codepad.viper-7.com/clum0f
However, that timestamp is actually for October 18, 2012: http://www.onlineconversion.com/unix_time.htm
I'm sure it's me, and not PHP, so what am I doing wrong? The code is pretty straightforward, so I can't figure it out.
Upvotes: 0
Views: 119
Reputation: 95101
n
= Numeric representation of a month, without leading zerosd
= Day of the month, 2 digits with leading zerosYou should replace
$dateTime->format('F n, Y');
With
$dateTime->format('F d, Y');
Upvotes: 2
Reputation: 67502
You are using format 'F n, Y'
. n
is a numeric representation of the month (October is month 10). Use d
(leading zeroes) or j
(no leading zeroes). See PHP date()
reference.
echo $dateTime->format('F d, Y');
Upvotes: 2