laravel 碳解析到 ISO8601
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/52525047/
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
Carbon parse to ISO8601
提问by Aladin Small
I am trying to get the current time and format it like:
我正在尝试获取当前时间并将其格式化为:
"2018-09-26T21:40:29+02:00"
But when I try:
但是当我尝试:
$isoDate = \Carbon\Carbon::now()->format('c');
as I understood passing a c
to format function will parse it to iso8601 but clearly thats not the case.
据我了解,传递c
to format 函数会将其解析为 iso8601,但显然情况并非如此。
Any help on how to parse current time to ISO8601 OR 20181001T094006Z
关于如何解析当前时间的任何帮助 ISO8601 OR 20181001T094006Z
采纳答案by Devon
There is no single 8601 format. 8601 defines various acceptable formats, of which PHP's c
represents one of the most common forms.
没有单一的 8601 格式。8601 定义了各种可接受的格式,其中 PHPc
是最常见的格式之一。
There is no single character for the specific 8601 format you wish but a format of Ymd\THis\Z
should work. T
and Z
are literal, so escape them with a backslash to avoid them being interpreted in the format string. Be sure that only UTC timestamps are used with this particular format.
您希望的特定 8601 格式没有单个字符,但Ymd\THis\Z
应该使用一种格式。 T
和Z
是文字,所以用反斜杠将它们转义以避免它们在格式字符串中被解释。请确保此特定格式仅使用 UTC 时间戳。
http://php.net/manual/en/function.date.phplists all the acceptable format characters.
http://php.net/manual/en/function.date.php列出了所有可接受的格式字符。
回答by Nurdin Aidanov
echo Carbon::now()->toIso8601String();
回答by Rana Nadeem
Carbon::now()->toISOString()
this will return "2020-05-12T13:13:42.817684Z"
这将返回 “2020-05-12T13:13:42.817684Z”
Carbon::now()->toIso8601String()
this will return "2020-05-12T13:15:32+00:00"
这将返回 “2020-05-12T13:15:32+00:00”