Skip to main content

Date Formatting (os.date)

os.date The second parameter is optional and defaults to current time.

FormatExampleDescriptionOutput
%Y-%m-%d %H:%M:%Sos.date("%Y-%m-%d %H:%M:%S", 1487356783)Common datetime format2017-02-18 02:39:43
%Y-%m-%dos.date("%Y-%m-%d", 1487356783)Common date format2017-02-18
%aos.date("%a", 1487356783)Abbreviated weekdaySat
%Aos.date("%A", 1487356783)Full weekdaySaturday
%bos.date("%b", 1487356783)Abbreviated monthFeb
%Bos.date("%B", 1487356783)Full monthFebruary
%cos.date("%c", 1487356783)Locale date and timeSat Feb 18 02:39:43 2017
%dos.date("%d", 1487356783)Day of month [01-31]18
%Hos.date("%H", 1487356783)Hour (24h) [00-23]02
%Ios.date("%I", 1487356783)Hour (12h) [01-12]02
%jos.date("%j", 1487356783)Day of year [001-366]049
%Mos.date("%M", 1487356783)Minute [00-59]39
%mos.date("%m", 1487356783)Month [01-12]02
%pos.date("%p", 1487356783)AM/PMAM
%Sos.date("%S", 1487356783)Second [00-61]43
%wos.date("%w", 1487356783)Weekday (Sunday=0) [0-6]6
%xos.date("%x", 1487356783)Locale date02/18/17
%Xos.date("%X", 1487356783)Locale time02:39:43
%yos.date("%y", 1487356783)Year without century17
%Yos.date("%Y", 1487356783)Year with century2017
%%os.date("%%", 1487356783)A percent sign%

More os.date usage examples
Show current date/time in real-time