我想將時間字符串轉換爲datetime與子午線,但我得到錯誤的日期時間。
這裏是我的代碼:php日期時間和區域
$timeZone = 'Europe/Warsaw';
date_default_timezone_set($timeZone);
$millis = 1540399680000;
$seconds = $millis/1000;
$date = date("d/m/Y H:i:s a", $seconds);
debug($date);
$timeZone = new DateTimeZone('Europe/Warsaw');
$formato = "d/m/Y H:i:s a";
$fecha = DateTime::createFromFormat($formato, $date, $timeZone);
debug($fecha);
debug($fecha->format('Y'));
debug($fecha->format('a'));
結果進行調試($日期)
24/10/2018 18:48:00 pm
結果進行調試($出生日期)
object(DateTime) {
date => '2018-10-25 06:48:00.000000'
timezone_type => (int) 3
timezone => 'Europe/Warsaw'
}
什麼,我期待在調試( $出生日期); date => '2018-10-24 06:48:00.000000'
你期望得到什麼? – alistaircol
'$ fecha'這是一個日期時間對象,您可以根據需要進行格式化。 – tarikul05
'debug($ fecha-> format('d/m/Y H:i:s a'));'它會給你想要的解決方案 – tarikul05