php - 如何在偏移量中没有冒号的情况下格式化PHP中的日期? [英] How to format a date in PHP without a colon in the offset?
问题描述
所以我有这个:
date('c')
格式如下:
2010-08-17T08:55:14-07:00
但是我需要一种方法来使偏移量中没有冒号,所以它可能看起来像这样:
but I need a way to not have the colon in the offset, so maybe it would look like this:
2010-08-17T08:55:14-0700
对此有什么解决方案?我希望使用稍微不同的格式,而不是获取字符串并替换最后一个冒号(使用 reg-ex 或其他东西).
What solution is there for this? I'm hoping for a slightly different format, rather than getting the string and replacing the last colon (using reg-ex or something).
推荐答案
从组成部分构建它:
date('Y-m-d\TH:i:sO')
有关不同格式字符串的信息,请参阅 date
文档.
See the date
documentation for the different format strings.
你感兴趣的是O
:
与格林威治时间 (GMT) 的小时数差异(例如:+0200)
Difference to Greenwich time (GMT) in hours (Example: +0200)
代替P
:
格林威治时间 (GMT) 的差异,小时和分钟之间带有冒号(在 PHP 5.1.3 中添加)(示例:+02:00)
Difference to Greenwich time (GMT) with colon between hours and minutes (added in PHP 5.1.3) (Example: +02:00)
这篇关于php - 如何在偏移量中没有冒号的情况下格式化PHP中的日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!