Last active
July 10, 2016 15:56
Star
You must be signed in to star a gist
International version of strtotime()
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
<?php | |
/** | |
* Version of strtotime() that doesn't use American dates. | |
* | |
* `strtotime()` interprets a date with slashes as American - i.e. m/d/y. So we | |
* replace all slashes with dashes, to stop it from doing this. | |
* | |
* @author chris barnes <chris@cjbarnes.co.uk> | |
* @link http://www.cjbarnes.co.uk/blog/2016-07-10-using-strtotime-outside-us/ | |
* | |
* @param string $time A date/time string. | |
* @param int $now Optional. The timestamp which is used as a base for the | |
* calculation of relative dates. | |
* @return string The strtotime() output. | |
*/ | |
function world_strtotime($time, $now = null) { | |
if (is_null($now)) { | |
$now = time(); | |
} | |
$str = str_replace('/', '-', $time); | |
return strtotime($time, $now); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment