Format Timezone for Carbon Date

本小妞迷上赌 提交于 2020-01-01 03:54:08

问题


I'm trying to set the timezone for a date in a Carbon object. It works fine locally but on my production box it keeps giving me Bad timezone error.

I've tried:

$date->setTimezone('7');
$date->setTimezone('+7');
$date->setTimezone('7:00');
$date->setTimezone('+7:00');
$date->setTimezone('UTC 7');
$date->setTimezone('UTC +7');
$date->setTimezone('UTC 7:00');
$date->setTimezone('UTC +7:00');

No idea why it's complaining on my production box. Can't find documentation either on what is the "proper" format to enter here. Can someone please help.

FYI: local is windows, and prod is Ubuntu box.


回答1:


You can change the timezone with this:

$timestamp = '2014-02-06 16:34:00';
$date = Carbon::createFromFormat('Y-m-d H:i:s', $timestamp, 'Europe/Stockholm');
$date->setTimezone('UTC');

this format working fine to my Local(Ubuntu) and prod(Redhat) project.




回答2:


I think you should refer to the official php timezone list. In your case you can use

$date->setTimezone('Asia/Phnom_Penh');

for UTC+7:00.



来源:https://stackoverflow.com/questions/28600330/format-timezone-for-carbon-date

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!