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

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

问题描述

如何转换(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 中?

推荐答案

试试这个

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

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

完整的日期函数文档可以在这里找到:http://php.net/手册/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.

希望我能帮上忙:)

附言:以防万一 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)));

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

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