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
How to convert ISO Date to DateTime in php?
提问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 MongoDate
object (this is probably your case), you can convert it to a DateTime
object 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);