如何将ISO8601转换为php中的日期格式 [英] How to convert ISO8601 to Date format in php

查看:483
本文介绍了如何将ISO8601转换为php中的日期格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何转换( ISO8601格式: 2014-03-13T09:05:50.240Z

How to convert this (in ISO8601 format): 2014-03-13T09:05:50.240Z

为此(在MySQL DATE格式):2014-03-13

To this (in MySQL DATE format): 2014-03-13

在php? p>

in php?

推荐答案

尝试这个

$date = '2014-03-13T09:05:50.240Z';

$fixed = date('Y-m-d', strtotime($date));

完整的日期功能文档可以在这里找到: http://php.net/manual/en/function.date.php

The complete date function documentation can be found here: http://php.net/manual/en/function.date.php

PHP函数strtotime不会将你的时间戳转换成unix时间戳。

The PHP function "strtotime" does nothing else then converting your timestring into an unix timestamp.

希望我可以帮助:)

Ps:
为了防止strtotime将返回0尝试使用这个:

P.s.: Just in case strtotime will return 0 try using this:

$date = '2014-03-13T09:05:50.240Z';

$fixed = date('Y-m-d', strtotime(substr($date,0,10)));

这篇关于如何将ISO8601转换为php中的日期格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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