Skip to content

Instantly share code, notes, and snippets.

@stuartpb
Created May 4, 2011 19:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stuartpb/955912 to your computer and use it in GitHub Desktop.
Save stuartpb/955912 to your computer and use it in GitHub Desktop.
--table of Windows Time Display Notation specifiers
--(http://support.microsoft.com/kb/307938) to the equivalent
--format specifiers for the Visual C++ Runtime Library's
--version of strftime (http://msdn.microsoft.com/en-us/library/fe06s4ak.aspx).
local wtdn2sftf = {
--'t' does only the first character of %p:
--no strftime equivalent
tt = 'p',
H = '#H',
h = '#I',
HH = 'H',
hh = 'I',
m = '#M',
mm = 'M',
s = '#S',
ss = 'S',
d = '#d',
dd = 'd',
ddd= 'a',
dddd='A',
M = '#m',
MM = 'm',
y = '#y',
yy = 'y',
yyy= '#Y', --undocumented
yyyy='Y',
}
local function wtdnftime(format, time)
format = format or "%c"
time = time or os.time()
return os.date(string.gsub(format,
"([thHmsdMy]*)",function(spec)
if wtdn2sftf[spec] then return '%'..wtdn2sftf[spec]
else return spec end
end),time)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment