laravel 使用语言环境将字符串日期转换为碳时间戳
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42201500/
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
Converting String Date To Carbon Timestamp with Locale
提问by senty
I have a date in string format, "Mon, 13 Feb 2017 09:30:00 GMT". I am trying to cast it to Carbon timestamp but I couldn't manage how. How can I use the GMT? What is the proper way?
我有一个字符串格式的日期,“星期一,2017 年 2 月 13 日 09:30:00 GMT”。我正在尝试将其转换为 Carbon 时间戳,但我无法管理如何。我如何使用格林威治标准时间?什么是正确的方法?
$date = 'Mon, 13 Feb 2017 09:30:00 GMT';
Carbon::createFromFormat('D, d m Y H:i:s', $date)->toDateTimeString());
采纳答案by Jethro Hazelhurst
You will want to get the time_zone string for example Europe/Paris
and pass it in as a parameter, for example:
例如,您需要获取 time_zone 字符串Europe/Paris
并将其作为参数传递,例如:
Carbon::createFromFormat('D, d M Y H:i:s e', $date, 'Europe/Paris')->toDateTimeString();
If you want GMT just use
如果你想要 GMT 只需使用
Carbon::createFromFormat('D, d M Y H:i:s e', $date, 'UTC')->toDateTimeString();
It is one of the first things that comes up in the Carbon documentation...
这是 Carbon 文档中出现的第一件事......
Carbon::createFromFormat($format, $time, $tz);