Last active
December 24, 2015 03:09
-
-
Save murdaugh/6735164 to your computer and use it in GitHub Desktop.
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 | |
function my_strftime($format,$time=null) { | |
global $my_locale; //this is set in the header as either en_US or es_ES | |
if($time == null) $time = time(); //if the time isn't passed in, then use the current timestamp | |
if($my_locale == "en_US") return strftime($format,$time); //If it's american english, just format the time as requested | |
else { //in my case, the only other option is es_ES, but this could be changed for whatever purposes you have | |
global $es_locale_string; | |
// we only care about day names and abbreviations and | |
// month names and abbreviations, so let's turn those | |
// into integers. and then get them out of the | |
// es_locale_string which has been shared here: | |
// https://gist.github.com/murdaugh/6734488 | |
$format = str_replace("%a", $es_locale_string["weekday_abbrev"][strftime("%w",$time)], $format); //day abbreviation | |
$format = str_replace("%A", $es_locale_string["weekday"][strftime("%w",$time)], $format); //day name | |
$format = str_replace("%b", $es_locale_string["month_abbrev"][strftime("%m",$time)-1], $format); //month abbreviation (it's 1-based index - hence the subtraction) | |
$format = str_replace("%B", $es_locale_string["month"][strftime("%m",$time)-1], $format); //month abbreviation (it's 1-based index - hence the subtraction) | |
return strftime($format,$time); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment