PublicHax Posted June 5, 2021 Posted June 5, 2021 Description os.date - Returns the date and time as a string or table. The first argument takes the format, the second argument takes the time in seconds. If you omit the 2nd argument, the function will return the current date and time. If the function is called without arguments, it will return the current date / time as 24/06/17 15:13:58. Syntax Snap to window: no. Working with a minimized window: yes. All parameters are enclosed in parentheses and separated by commas. os.date ([format [, time]]) Where: format is an optional parameter. Enclosed in quotation marks (for example: os.date ("% X")). If the format is "* t", it returns a table: year (year, four digits) month (month, 1 - 12) day (day, 1 - 31) hour (hour, 0 - 23) min (minutes, 0 - 59) sec (seconds, 0 - 61) wday (day of the week, Sunday equals 1) yday (day of the year) isdst (daytime flag, boolean type). If the format is not equal to "* t", then the function returns the date as a string. The format can be given: % a - day of the week, abbreviated English. % A - day of the week, fully English. % b - month, abbreviated English. % B - month, fully English. % c - date and time (by default) in the format: 24/06/17 15:13:58) % d - day of the month % H - hour, in 24-hour format % I - hour, in 12 hour format % M - minute % m - month % p - time of day "am" or "pm" % S - second % w - day of the week (0 - 6 corresponds to Sunday-Saturday) % x - date in the format: 24/06/17 % X - time in the format: 15:13:58 % Y - year (4 digits) % y - year, (2 digits) %% - symbol "%" * t - will return the table ! * t - will return the table (GMT) time is an optional parameter. If not specified, the function will return the current time. Examples of --lua log ("clear") log ("mode compact") local date_time = os.date () - assign date and time to a variable log (date_time) - output to the log --lua log ("clear") log ("mode compact") local arr = os.date ("* t") log ("Year:" .. arr.year) log ("Month:" .. arr.month) log ("Day:" .. arr.day) log ("Hour:" .. arr.hour) log ("Minutes:" .. arr.min) log ("Seconds:" .. arr.sec) log ("Day of the week:" .. arr.wday) log ("Day of the year:" .. arr.yday) --lua log (os.date ("% X")) - log the current time log (os.date ("% B")) - month log (os.date ("% H")) - hour log (os.date ("% H:% M")) - hour and minutes --lua - the function returns the data type string, this must be taken into account when comparing if os.date ("% H") == "12" then - compare as string log ("It is 12 o'clock") else log ("It is not 12 o'clock") end if tonumber (os.date ("% H")) == 12 then - compare as a number log ("It is 12 o'clock") else log ("It is not 12 o'clock") end --lua - find out the day of the week log (os.date ("% A", os.time ({year = 2017, month = 06, day = 25}))) --lua log (os.date ("% d.% m.% Y")) - current date --lua log (os.date ("It is now% H hours% M minutes% S seconds"))
Recommended Posts
Archived
This topic is now archived and is closed to further replies.