Skip to content

Instantly share code, notes, and snippets.

@ianlandsman
Created September 25, 2012 14:05
Show Gist options
  • Save ianlandsman/3782120 to your computer and use it in GitHub Desktop.
Save ianlandsman/3782120 to your computer and use it in GitHub Desktop.
Windows strftime Hack
function strftime_win32($format, $ts = null) {
if (!$ts) $ts = time();
$mapping = array(
'%C' => sprintf("%02d", date("Y", $ts) / 100),
'%D' => '%m/%d/%y',
'%e' => sprintf("%' 2d", date("j", $ts)),
'%h' => '%b',
'%n' => "\n",
'%r' => date("h:i:s", $ts) . " %p",
'%R' => date("H:i", $ts),
'%t' => "\t",
'%T' => '%H:%M:%S',
'%u' => ($w = date("w", $ts)) ? $w : 7
);
$format = str_replace(
array_keys($mapping),
array_values($mapping),
$format
);
return strftime($format, $ts);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment