The PHP manual for DateTime states
The $timezone parameter and the current timezone are ignored when the $time开发者_Go百科 parameter either is a UNIX timestamp (e.g. @946684800) or specifies a timezone (e.g. 2010-01-28T15:00:00+02:00).
Which means that when I do
$time1 = new DateTime('@'.time());
$time2 = new DateTime();
I will have two different results since my default timezone is not UTC. How do you handle this? I don't want to change my server timezone - yet I need timestamps to be output in my timezone.
Use:
$time1 = new DateTime(NULL, "<your timezone here>");
Or you can specify your preferred format in the first field and leave the timezone NULL.
精彩评论