php 碳日期的格式时区
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28600330/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Format Timezone for Carbon Date
提问by Rob
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.
我正在尝试为Carbon
对象中的日期设置时区。它在本地工作正常,但在我的生产盒上它一直给我Bad timezone
错误。
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.
仅供参考:local 是 windows,prod 是 Ubuntu box。
回答by Safoor Safdar
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.
这种格式适用于我的本地(Ubuntu)和 prod(Redhat)项目。
回答by Anton Egorov
I think you should refer to the official php timezone list. In your case you can use
我认为你应该参考官方的 php timezone list。在您的情况下,您可以使用
$date->setTimezone('Asia/Phnom_Penh');
for UTC+7:00.
UTC+7:00。