我有一个这样的变量,
$Timestamp = "Tue Mar 8 15:59:00 UTC-05:00 2016";
如何将其格式更改为YYYYMM-DD HH:MM AM / PM并使用PHP将时区从UTC更改为太平洋时间?
答案 0 :(得分:2)
PHP的DateTime对象非常灵活。
$UTC = new DateTimeZone("UTC");
$TZ = new DateTimeZone("America/New_York");
$date = new DateTime( "2016-03-09 15:00:00", $UTC );
$date->setTimezone( $TZ );
echo $date->format('Y-m-d H:i:s');
答案 1 :(得分:0)
使用php date:
date('Y/m/d H:i', $timestamp)但你的时间戳应为int:
$timestamp = strtotime('22-09-2008');
答案 2 :(得分:0)
您可以尝试以下
$Timestamp = "Tue Mar 1 15:59:00 UTC-05:00 2016";
$datetime = new DateTime($Timestamp);
$datetime->format('Y-m-d H:i:s') . "\n";
$new_time = new DateTimeZone('Pacific/Apia');
$datetime->setTimezone($new_time);
//New formatted time
echo $datetime->format('Y-m-d H:i:s');