Date Conversion from ISO 8601 To RFC 2822 format
Posted: Sat Apr 07, 2007 12:14 pm
Extremely long function name. Quick and dirty.
This got me thinking: there must be a better way to do this! The function only accepts GMT style ISO 8601 dates. I am using this function to convert Subversion timestamps into RSS timestamps.
Example:
Outputs: Thu, 01 Jan 1970 00:00:00 +0000
Code: Select all
function convertDateFromISO8601ToRFC2822($date) {
preg_match('/(\d+)-(\d+)-(\d+)T(\d+):(\d+):(\d+).(\d+)Z/',
$date, $time_matches);
list($x, $year, $month, $day, $hour, $minute, $second) =
$time_matches;
$timestamp = gmmktime($hour, $minute, $second, $month, $day, $year);
return gmdate('r', $timestamp);
}Example:
Code: Select all
echo convertDateFromISO8601ToRFC2822('1970-01-01T00:00:00Z');