Jump to content

Timestamp Conversion RSS to unix


monkeytooth

Recommended Posts

Whats the best way to convert "Tue, 22 Sep 2009 04:00:40 GMT" to a unix timestamp, im looking around, playing around and I can't seem to get it to work right. I know I should tempt to phase it like "2009-09-22 04:01:00" and pump it through date() but some of the things I am working on currently are 3rd party and I have no control over their outputs.

Link to comment
https://forums.phpfreaks.com/topic/175101-timestamp-conversion-rss-to-unix/
Share on other sites

Hi monkeytooth,

 

If you break your time string down into its relevant parts, you could then use mktime() to convert it into a UNIX timestamp.

 

i.e.

 

mktime($hour, $minute, $second, $month, $day, $year)

 

You could use the strtotime() also but would have to format the string correctly (US English date format).  So that again would require you break the string down into its relevant parts.

 

Hope this helps.

The reason I posted strtotime() was that I tested it and found it to work. It supports other formats than the standard YYYY-MM-DD HH:MM:SS.

 

<?php
$date = 'Tue, 22 Sep 2009 04:00:40 GMT';
$stamp = strtotime($date);
//check timestamp by reverting the operation
echo gmdate('D, j M Y H:i:s T', $stamp);
//Tue, 22 Sep 2009 04:00:40 GMT
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.