碳解析度符合ISO8601 [英] Carbon parse to ISO8601

查看:70
本文介绍了碳解析度符合ISO8601的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取当前时间并将其格式设置为:

I am trying to get the current time and format it like:

"2018-09-26T21:40:29+02:00"

但是当我尝试:

$isoDate = \Carbon\Carbon::now()->format('c');

据我了解,将 c 传递给格式化函数会将其解析为iso8601,但显然不是这种情况.

as I understood passing a c to format function will parse it to iso8601 but clearly thats not the case.

有关如何将当前时间解析为 ISO8601或20181001T094006Z

Any help on how to parse current time to ISO8601 OR 20181001T094006Z

推荐答案

没有单一的8601格式.8601定义了各种可接受的格式,其中PHP的 c 表示最常见的格式之一.

There is no single 8601 format. 8601 defines various acceptable formats, of which PHP's c represents one of the most common forms.

您想要的特定8601格式没有单个字符,但是 Ymd \ THis \ Z 格式应该可以. T Z 是文字,因此请使用反斜杠对其进行转义,以免它们在格式字符串中被解释.确保仅将UTC时间戳与此特定格式一起使用.

There is no single character for the specific 8601 format you wish but a format of Ymd\THis\Z should work. T and Zare 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.

http://php.net/manual/en/function.date.php 列出所有可接受的格式字符.

http://php.net/manual/en/function.date.php lists all the acceptable format characters.

这篇关于碳解析度符合ISO8601的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆