Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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:
$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