[英]PHP Converting DATE+TIME+TIMEZONE to DATE+TIME+NEW-TIMEZONE PHP
我從客戶那里得到了這個 php output
2022 年 4 月 30 日星期六 19:23:03 GMT+0800(中國標准時間)
我希望在新時區進行轉換,問題是我無法控制上面的數據 sa 我必須將所有 output 轉換為新時區,即布里斯班時區
像這樣
$current_date_time_timezone = "Sat Apr 30 2022 19:23:03 GMT+0800 (China Standard Time)"
$timeBrisbane = new DateTimeZone('Australia/Brisbane');
$date_time_new_timezone = $date_time_new_timezone->setTimezone($timeBrisbane);
echo $date_time_new_timezone->format('Y-m-d H:i:s');
上面的output返回錯誤,
我要的output是這樣的:
輸出= "Sat Apr 30 2022 19:23:03 GMT+10 (Australia/Brisbane)"
您可以使用DateTime::createFromFormat()
將該初始字符串解析為 DateTime object。
由於時區偏移量在“GMT”之后已經存在,因此我將忽略括號部分:
$current_date_time_timezone = "Sat Apr 30 2022 19:23:03 GMT+0800 (China Standard Time)";
$timeBrisbane = new DateTimeZone('Australia/Brisbane');
$date_time_new_timezone = DateTime::createFromFormat("D M j Y H:i:s \G\M\TO+", $current_date_time_timezone);
$date_time_new_timezone->setTimezone($timeBrisbane);
echo $date_time_new_timezone->format("D M j Y H:i:s \G\M\TO \(e\)");
// Sat Apr 30 2022 21:23:03 GMT+1000 (Australia/Brisbane)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.