PHP DateTime DST

后端 未结 1 627
夕颜
夕颜 2020-12-21 05:10

I searched the PHP manual and StackOverflow too, but haven\'t really found a proper answer to my question. My dates are stored in UTC. Now if I do:

$date = n         


        
相关标签:
1条回答
  • 2020-12-21 06:12

    Your assumption is correct.

    In addition, this would have taken you 10 seconds to verify yourself.

    Edit:

    The correct syntax is:

    $date = new DateTime('2012-03-16 14:00:00', new DateTimeZone('UTC'));
    

    As to your second question. The timezone passed in the DateTime constructor is the 'reference' timezone.

    You should still call ->setTimeZone(new DateTimeZone('UTC')) to format it in the UTC timezone, unless the default timezone was also set to UTC (date_default_timezone_set).

    Next time, try a little harder trying stuff out before asking.

    0 讨论(0)
提交回复
热议问题