Created
October 2, 2008 20:27
-
-
Save wtnabe/14435 to your computer and use it in GitHub Desktop.
Convert RFC1123-style time differences to N-seconds (PHP)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Convert RFC1123-style time differences to N-seconds | |
* | |
* If unixtime is given, convert first it to RFC1123-style time | |
* differences by date( "O" ). | |
* | |
* @since 2008-10-03 | |
* @param string | |
* @return int | |
*/ | |
function td2sec( $str ) { | |
if ( preg_match( '/\A[0-9]+\z/', $str ) > 0 ) { | |
$str = date( "O", $str ); | |
} | |
if ( preg_match( '/\A([+-])([0-9]{2})([0-9]{2})\z/', $str, $match ) > 0 ) { | |
return sprintf( "%s%d", | |
$match[1], | |
(int)$match[2] * 3600 + (int)$match[3] * 60 ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment