开发者

How do you get around PHP's DateTime usage of UTC for timestamps?

开发者 https://www.devze.com 2023-02-09 00:17 出处:网络
The PHP manual for DateTime states The $timezone parameter and the current timezone are ignored when the

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消