PHP将日期更改为Y-m-d H:i[复制]

时间:2022-06-18 21:28:43

This question already has an answer here:

这个问题已经有了答案:

What I Require

How can I convert 2013-07-26T10:00:00.000+05:30 to Y-m-d H:i:s format.

我怎样才能把2013-07-26 t10:00 +05:30转换到Y-m-d H: s格式。

I need to get 2013-07-26 10:00:00 from this.

我需要从这里得到2013-07-26 10:00:00。

.

What I Tried

 $dateTime = DateTime::createFromFormat(DateTime::ISO8601,2013-07-26T10:00:00.000+05:30);
 echo $dateTime->format('Y-m-d H:i:s');

AND

 $dateTime = DateTime::createFromFormat(DateTime::ISO8601, srtotime(2013-07-26T10:00:00.000+05:30));
 echo $dateTime->format('Y-m-d H:i:s');

Note: The date was obtained from google calendar's event start and end date.

注意:日期是从谷歌日历的事件开始和结束日期获得的。

3 个解决方案

#1


2  

Use DateTime

使用日期时间

$date = new DateTime('2013-07-26T10:00:00.000+05:30');
echo $date->format('Y-m-d H:i:s');

#2


2  

The second argument for createFromFormat should be the string representing the time, not a timestamp. Try removing strtotime and passing in the string directly.

createFromFormat的第二个参数应该是表示时间的字符串,而不是时间戳。尝试删除strtotime并直接传入字符串。

Alternatively you could do:

或者你可以做的:

echo date('Y-m-d H:i:s', strtotime('2013-07-26T10:00:00.000+05:30'));

#3


0  

Try this code

试试这个代码

$datetime="2013-07-26T10:00:00.000+05:30";
$time=strtotime($datetime);
echo date("Y-m-d H:i:s",$time);

#1


2  

Use DateTime

使用日期时间

$date = new DateTime('2013-07-26T10:00:00.000+05:30');
echo $date->format('Y-m-d H:i:s');

#2


2  

The second argument for createFromFormat should be the string representing the time, not a timestamp. Try removing strtotime and passing in the string directly.

createFromFormat的第二个参数应该是表示时间的字符串,而不是时间戳。尝试删除strtotime并直接传入字符串。

Alternatively you could do:

或者你可以做的:

echo date('Y-m-d H:i:s', strtotime('2013-07-26T10:00:00.000+05:30'));

#3


0  

Try this code

试试这个代码

$datetime="2013-07-26T10:00:00.000+05:30";
$time=strtotime($datetime);
echo date("Y-m-d H:i:s",$time);