$dt = '2013-03-15 02:15:33';
$dateTimeZone = new DateTimeZone('Asia/Karachi');
$dateTime = new DateTime($dt, $dateTimeZone);
$year = $dateTime->format('Y');
$month = $dateTime->format('m');
$day = $dateTime->format('d');
$hours = $dateTime->format('H');
$minutes = $dateTime->format('i');
$seconds = $dateTime->format('s');
$message_time_ago = $year . '-' . $month . '-' . $day . ' ' . $hours . ':' . $minutes. ':' . $seconds;
但它返回相同的“2013-03-15 02:15:33”,但它应该是“2013-03-15 11:15:33”。 谁能帮我解决这个问题吗?
最佳答案
这就是你的做法:
$date = new DateTime('2013-03-15 02:15:33');
$date->setTimezone(new DateTimeZone('Asia/Karachi'));
echo $date->format('Y-m-d H:i:s'); // 2013-03-15 07:15:33
关于php - 如何在 PHP 中将日期和时间字符串转换为当前时区日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23602613/