将字符串(ISO)转换为日期PHP [英] Convert String (ISO) to Date PHP

查看:146
本文介绍了将字符串(ISO)转换为日期PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将字符串转换为 PHP 中的日期。我收到的字符串的格式为:-

I am trying to convert a string to a date in PHP. The string I receive is formatted:-

"2016-07-16T1:22:04.324+1030"

OR

"2016-12-20T03:24:59.000Z"

当我尝试此操作

$newDate = DateTime::createFromFormat("c", $exp);
$expirationDate = $newFormat->getTimestamp();

DateTime 失败。即使当我尝试

$newDate = DateTime::createFromFormat(ISO8601, $exp;
$expirationDate = $newFormat->getTimestamp();

DateTime 仍然失败。

任何建议都会受到赞赏。

Any suggestions are greatly appreciated.

推荐答案

您可以这样尝试:-

<?php

$time = "2016-07-16T1:22:04.324+1030";

echo date("d M, Y",strtotime(date($time)));

?>

输出:-2016年7月16日:- https://eval.in/594695

Output:- 16 Jul, 2016 :- https://eval.in/594695

参考:-

在PHP中将ISO 8601格式转换为d MY

注意:-您可以根据需要更改日期格式,例如 DM d Y h:i:s OT 。我在PH上检查了此代码P 5.5.4,PHP 5.5.14,PHP 7

Note:- you can change format of date according to your convenience. like D M d Y h:i:s O T . I checked this code on PHP 5.5.4 , PHP 5.5.14, PHP 7

这篇关于将字符串(ISO)转换为日期PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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