【发布时间】:2013-12-23 09:36:25
【问题描述】:
我正在尝试将 utc 时间存储日期转换为另一个时区,但我似乎无法正确处理。 我有时间:
date1 = new DateTime('first day of the month');
date1.setTime(0,0,0); // Since using the first day of the month seems return the current time with different date
默认的 DateTime 时区是 UTC。我想参考的时间是“欧洲/阿姆斯特丹”时区。有什么办法我不能让“欧洲/阿姆斯特丹”时区的时间等于 UTC 的每月第一天时间? (呃,对不起,我的问题令人困惑......让我举个例子来说明一下)。我正在尝试从数据库中查询。
If UTC date time is June 01, 2013. 00:00:00
I want to get get May 29, 2013 19:55:00.
我尝试获取不同时区的两个声明时间之间的差异,以获得我想要的时间,但它似乎没有用 :( 我的编辑/澄清:
如果使用此代码:
$date1 = new DateTime('first day of the month');
$date1.setTime(0,0,0);
print_r($date1->format('Y-m-d H:i:s'));
我会得到:
2013-06-01 00:00:00
如果我使用时区:
$date1->setTimeZone(new DateTimeZone('Europe/Amsterdame'));
print_r($date1->format('Y-m-d H:i:s'));
我会得到:(这只是一个示例输出):
2013-06-01 03:00:00
因为时差。我想要得到的结果就像相反:我想要得到转换为“UTC”时区的日期时间:06-01-2013 00:00:00 时间。所以我的首选输出是:2013-05-29 21:00:00 ...
【问题讨论】:
-
这不是有效的 PHP。
-
我完全看不出 6 月 1 日 00:00 UTC 与 5 月 29 日 19:55 阿姆斯特丹 有何关系。
-
@AmalMurali,嗯,我知道它无效。它是 PSUDOCODE.. =_=
-
@DamienOvereem 是的。我知道如何使用 setTimezone.. 我想我的问题真的不清楚.. 让我编辑它..