Date Formatting (os.date)
os.date The second parameter is optional and defaults to current time.
Format | Example | Description | Output |
---|---|---|---|
%Y-%m-%d %H:%M:%S | os.date("%Y-%m-%d %H:%M:%S", 1487356783) | Common datetime format | 2017-02-18 02:39:43 |
%Y-%m-%d | os.date("%Y-%m-%d", 1487356783) | Common date format | 2017-02-18 |
%a | os.date("%a", 1487356783) | Abbreviated weekday | Sat |
%A | os.date("%A", 1487356783) | Full weekday | Saturday |
%b | os.date("%b", 1487356783) | Abbreviated month | Feb |
%B | os.date("%B", 1487356783) | Full month | February |
%c | os.date("%c", 1487356783) | Locale date and time | Sat Feb 18 02:39:43 2017 |
%d | os.date("%d", 1487356783) | Day of month [01-31] | 18 |
%H | os.date("%H", 1487356783) | Hour (24h) [00-23] | 02 |
%I | os.date("%I", 1487356783) | Hour (12h) [01-12] | 02 |
%j | os.date("%j", 1487356783) | Day of year [001-366] | 049 |
%M | os.date("%M", 1487356783) | Minute [00-59] | 39 |
%m | os.date("%m", 1487356783) | Month [01-12] | 02 |
%p | os.date("%p", 1487356783) | AM/PM | AM |
%S | os.date("%S", 1487356783) | Second [00-61] | 43 |
%w | os.date("%w", 1487356783) | Weekday (Sunday=0) [0-6] | 6 |
%x | os.date("%x", 1487356783) | Locale date | 02/18/17 |
%X | os.date("%X", 1487356783) | Locale time | 02:39:43 |
%y | os.date("%y", 1487356783) | Year without century | 17 |
%Y | os.date("%Y", 1487356783) | Year with century | 2017 |
%% | os.date("%%", 1487356783) | A percent sign | % |
More os.date usage examples
Show current date/time in real-time