Reputation: 155
How to convert the ISO date in mongodb:
ISODate("2015-11-20T10:00:09.809Z")
to php date ?
Upvotes: 0
Views: 7542
Reputation: 1
when you extract ISODate("2015-11-20T10:00:09.809Z") from MongoDB you will get two different timestamps for date=>sec and time=>usec
Example:
"created_at":{"sec":1592249762,"usec":53000}
Then you can add both sec and usec and you will get new timestamp.
$newTimeStamp = $created_at->sec+$created_at->usec;
echo date('Y-m-d H:i:s', $newTimeStamp);
Upvotes: 0
Reputation: 19285
You should check 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:
//get a DateTime object
$phpDate = $mongoDate->toDateTime();
And finally convert it to the format you want:
$phpDate->format('M-d-Y');
Upvotes: 3
Reputation: 90
$date = '2011-09-02T18:00:00';
$time = strtotime($date);
$fixed = date('l, F jS Y \a\t g:ia', $time);
Upvotes: 0