I just got some tweets using their XML feed, and have gotten the date/times like so
Tue Sep 29 22:30:51 +0000 2009
I tried using strtotime() on this, but it wasn’t producing the correct results.
I later on use
echo date($dateTimeFormat, $twitterUnixTime);
I know I could use a regex, but from the looks of it it will be complicated (and will need to use a callback, to convert ‘Sep’ to a numeral. From what I understand, strtotime() can easily do MySQL dates (2009-09-30 13:00:00) and some others (generally from RSS feeds).
What can I do here to get this date/time as an Unix Epoch time?
UPDATE
Here is my code
$dateTime = $status->created_at; // Tue Sep 29 22:30:51 +0000 2009
$date = strtotime($dateTime);
$dateTimeFormat = 'j/n/y g:ia';
echo date($dateTimeFormat, $date); // 2/2/09 12:01am
UPDATE
Sorry guys, entirely my fault. I have a variable mistyped. Thanks for your answers!
What is exactly the problem you are getting with
strtotime?Using this code :
I get this output :
So, wrong by 2 hours — is that the kind of problem you have ?
If yes, it might be a problem of timezone : I am in France, and there is a difference of 2 hours with GMT/UTC time.
Changing locale with the
date_default_timezone_setfunction (to set one that is in the GMT timezone), with this line before the previous ones :Gets this as output :
Which kind of look like the desired result ?
You might also change the
date.timezonesetting inphp.ini; but might have some other impacts, so not sure it’s that much of a good idea…Maybe you could use the “
UTC” timezone, btw, like this :Considering what we are willing to get/mean, it might actually be a better idea…