我正在尝试使用子午线转换为DateTime的一字符串,但我遇到了DateTime。
这是我的代码:
$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'));
debug的结果($ date(
24/10/2018 18:48:00 pm
debug($ fecha(的结果
object(DateTime) {
date => '2018-10-25 06:48:00.000000'
timezone_type => (int) 3
timezone => 'Europe/Warsaw'
}
我期望的是Debug($ FECHA(; date => '2018-10-24 06:48:00.000000'
您是否尝试使用caketime ::格式((?F.Ex。:
$date = CakeTime::format($seconds, 'd/m/Y H:i:s a', false, 'Europe/Warsaw');
debug($date);
基于文档(http://php.net/manual/manual/en/datetime.createfromformat.php(,dateTime create createformat函数返回dateTime对象。如果要获得直接输出,请按照此代码。
$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";
// instead of this
//$fecha = DateTime::createFromFormat($formato, $date, $timeZone);
// add ->format in the end
$fecha = DateTime::createFromFormat($formato, $date, $timeZone)->format($formato);
debug($fecha);