I have a string $StartDate = "2015-09-23"
(should be like yyyy-mm-dd). Than I make $UdtStart= strtotime($StartDate)
that returns 1442980800; Well if I go to this link it return back "Wed, 23 Sep 2015 04:00:00 +0000". First, why do we have 04:00:00 added?
Than, if I do this $back=gmdate("Y-m-d H:i:s", ($UdtStart)); I will have "2015-09-26 04:00:00".
What am I missing?
$UdtStart= strtotime($StartDate);
$back=gmdate("Y-m-d H:i:s", ($UdtStart));
Wed, 23 Sep 2015 04:00:00 +0000
Note that +0000
on the end, that means the time is UTC. As per the PHP strtotime() doco:
Each parameter of this function uses the default time zone unless a time zone is specified in that parameter.
The gmdate
is for Greenwich Mean Time (and really should be called something like utcdate
nowadays), so you're asking for the data in a different foramt from what you gave it.
I'd be willing to bet money that you're in a timezone four hours removed from UTC, which is why you're seeing that.
If you want local time, use date()
rather than gmdate()
. The gmdate
doco states:
Identical to the
date()
function except that the time returned is Greenwich Mean Time (GMT).
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments