ItsJamie
ItsJamie

Reputation: 261

How can I convert this to a timestamp?

2014-03-06T00:50:49.000Z

How can I convert this to a timestamp in PHP? It is given as a string:

$time = "2014-03-06T00:50:49.000Z";

Upvotes: 0

Views: 52

Answers (2)

vogomatix
vogomatix

Reputation: 5041

A slightly more OO way than the other answer...

<?php

$dt = new DateTime("2014-03-06T00:50:49.000Z");
echo $dt->getTimestamp();

I recommend this way because the DateTime class also has time manipulation and formatting methods. This is a class in 5.2.0+ , but there are implementations to mimic the DateTime class for earlier PHP versions.

Upvotes: 4

John Conde
John Conde

Reputation: 219824

strtotime() can handle that date format:

echo strtotime("2014-03-06T00:50:49.000Z");
// 1394067049

See it in action

Upvotes: 3

Related Questions