0
我有日期時間2017-10-11 09:40:42
亞洲/卡拉奇我想將其轉換爲unix時間戳。php將datetime轉換爲unixtime和時區
注:我有不同的時區例如多個記錄:澳大利亞/悉尼
我沒把它從下面的代碼轉換
function unixTimefromTime($thetime='now',$timezone){
if(is_numeric($thetime)){
$dt = new \DateTime('@'.$thetime);
$dt->setTimeZone(new \DateTimeZone($timezone));
return $dt->getTimestamp();
} else {
$date = new \DateTime($thetime, new \DateTimeZone($timezone));
return $date->getTimestamp();
}
}
unixTimefromTime('2017-10-11 09:40:42','Asia/Karachi');
嘗試[這](https://開頭計算器.com/questions/1670797/convert-date-to-unixtime-php) – Sand
它如何與時區一起工作? – user3151197
你可以請嘗試這個https://stackoverflow.com/questions/8668108/how-to-get-unix-timestamp-in-php-based-on-timezone – Abhijit