從「+00:00」和「+01:00」可以看出,這顯然是一個時區問題。 01:
您也可以通過與date_default_timezone_set
date_default_timezone_set("UTC");
2016-01-01T01之前設置默認的時區驗證這個01 + 00:00
見eval.in - UTC
VS
date_default_timezone_set("Europe/Berlin");
2016-01-01T02:01:01 + 01:00
見eval.in - Berlin
您還可以瞭解當地的時區與date_default_timezone_get
echo date_default_timezone_get();
eval.in - local timezone
UTC
這也解釋了爲什麼http://eval.in
顯示預期的輸出。
當然,你可以設置一個DateTime
對象的時區分別
$ts = 1451610061;
$dt = new DateTime("@$ts");
$utc = new DateTimeZone("UTC");
$dt->setTimezone($utc);
echo "UTC=", $dt->format('c'), "\n";
$berlin = new DateTimeZone("Europe/Berlin");
$dt->setTimezone($berlin);
echo "Berlin=", $dt->format('c'), "\n";
這將顯示
UTC = 2016-01-01T01:01:01 + 00: 00
Berlin = 2016-01-01T02:01:01 + 01:00
eval.in - setTimezone
到最後回答你的問題:有沒有你的代碼錯誤。 2016-01-01T02:01:01+01:00
是根據一個ISO 8601 - Wikipedia該時間戳的完全有效的表示。
根據[這](http://www.onlineconversion.com/unix_time.htm)網站,'1451610061'導致'週五,2016年1月1日1時01分01秒GMT'所以它的服務器問題。也許在'datetime'中添加'timezone'。 – Xorifelse
也適用於https://eval.in/725142 –