DateTime alters timestamp during DST winter change

拟墨画扇 提交于 2019-12-05 12:31:23

You said:

Timestamp is always in UTC and should be local time, timezone agnostic

That statement is in conflict with itself. Timestamps are in UTC, yes, but that is not local time or time zone agnostic.

Put another way, a timestamp always refers to a specific instant in time. A local time might be ambiguous, but a timestamp is not. If you wanted the first instance of the ambiguous local time, then specify a timestamp that is an hour earlier.

However, your data is slightly incorrect. The timestamp you specified, 1540686600, is actually not 1:30 UTC but rather it corresponds to 2018-10-28T01:30:00+01:00. Therefore, it is indeed the first occurrence of 1:30 on the day of the fall-back DST transition. The second occurrence would be 2018-10-28T01:30:00+00:00, which corresponds to 1540690200.

Regarding your second question:

is there any simple solution to keep both timezone id and intended timestamp in DateTime object?

That's already how DateTime works in PHP. It consists of an internal timestamp, and an associated time zone. That's exactly what you're showing when you call setTimezone.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!