Datetime:format([dateformat], [timeformat])method
Formats the Datetime value as a string.
Parameters
[dateformat]
An optional string representing the format for the date part. For only formatting the time part, use nil in place. The format tokens accepted are :
- Year : "y" or "yy" for short format of the Year, and "yyyy" for the long format.
- Month :"M" or "MM" for short format of the Month, and "MMMM" for the long format.
- Day : "d" or "dd" for short format of the Day, and "dddd" for the long format.
[timeformat]
An optional string representing the format for the time part. For only formatting the date part, omit that argument. The format tokens accepted are :
- Hours (12-hour clock): "h", or "hh" with a leading zero.
- Hours (24-hour clock): "H, or "HH" with aleading zero.
- Minutes :"m" or "mm" with a leading zero.
- Seconds : "s" or "ss" with a leading zero
- Time marker : "t or "tt" for AM/PM time marker.
Return value
This function returns the formatted string.Example
-- get current date and time
local today = sys.Datetime()
-- prints only the current time, not the date
print("Current time = "..today:format(nil, "HH:mm:ss"))