![](/img/trans.png)
[英]How to format a string with date/time and timezone to account for the timezone php
[英]How to convert the date & time string into current timezone date in PHP
$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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.