Skip to content

Instantly share code, notes, and snippets.

@cjbarnes
Last active July 10, 2016 15:56
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save cjbarnes/f2b9ee54ef93ff41c0c1b8116b289ec8 to your computer and use it in GitHub Desktop.
International version of strtotime()
<?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