laravel 如何在php中将ISO日期转换为DateTime?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34154618/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 12:47:42  来源:igfitidea点击:

How to convert ISO Date to DateTime in php?

phpmongodbdatelaraveldatetime

提问by user996581

How to convert the ISO date in mongodb:

如何在 mongodb 中转换 ISO 日期:

ISODate("2015-11-20T10:00:09.809Z") 

to php date ?

到 php 日期?

回答by Moppo

You should check MongoDate:

你应该检查MongoDate

//build a MongoDate object from a string format
$mongoDate = new MongoDate( strtotime("2010-01-15 00:00:00") );

Once you have a MongoDateobject (this is probably your case), you can convert it to a DateTimeobject this way:

一旦你有一个MongoDate对象(这可能是你的情况),你可以通过DateTime这种方式将它转换为一个对象:

//get a DateTime object
$phpDate = $mongoDate->toDateTime();

And finally convert it to the format you want:

最后将其转换为您想要的格式:

$phpDate->format('M-d-Y');

回答by anubhav

$date = '2011-09-02T18:00:00';

$date = '2011-09-02T18:00:00';

$time = strtotime($date);

$time = strtotime($date);

$fixed = date('l, F jS Y \a\t g:ia', $time);

$fixed = date('l, F jS Y \a\tg:ia', $time);