• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

没见过这种时间格式,如何用PHP格式化它

php 搞代码 3年前 (2022-01-25) 24次浏览 已收录 0个评论
文章目录[隐藏]

从某API中获取到的时间格式是这样的2014-10-30T15:59:59.999Z
PHP如何格式化它为正常的date例如Y-m-d H:i:s

回复内容:

从某API中获取到的时间格式是这样的2014-10-30T15:59:59.999Z
PHP如何格式化它为正常的date例如Y-m-d H:i:s

可以自己定义,现在都采用面向对象的方式来操作时间了,就是所谓的DateTime

有很多已经定义好的格式

<code> DateTime implements DateTimeInterface {/* 常量 */const string ATOM = "Y-m-d\TH:i:sP" ;const string COOKIE = "l, d-M-Y H:i:s T" ;const string ISO8601 = "Y-m-d\TH:i:sO" ;const string RFC822 = "D, d M y H:i:s O" ;const string RFC850 = "l, d-M-y H:i:s T" ;const string RFC1036 = "D, d M y H:i:s O" ;const string RFC1123 = "D, d M Y H:i:s O" ;const string RFC2822 = "D, d M Y H:i:s O" ;const string RFC3339 = "Y-m-d\TH:i:sP" ;const string RSS = "D, d M Y H:i:s O" ;const string W3C = "Y-m-d\TH:i:sP" ;……//http://php.net/manual/zh/class.datetime.php}</code>

上面格式化,代码如下

<code>$date = new DateTime('2014-10-30T15:59:59.999Z');echo $date->format('Y-m-d H:i:s');</code>

本@文来源gao($daima.com搞@代@#码(网5搞gaodaima代码

echo(date_format(date_create(‘2014-10-30T15:59:59.999Z’),’Y/m/d H:i:s’));
这么标准的ISO时间格式

怎么没人回复strtotime这个变态又常用的函数?

<code><?phpecho date("Y-m-d H:i:s", strtotime("2014-10-30T15:59:59.999Z"));//输出2014-10-30 23:59:59</code>

搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:没见过这种时间格式,如何用PHP格式化它

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址