How can you get the current OS time?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
How can you get the current OS time?
Is there a way to get the operating systems time that is cross platform? (ie Mac,Windows,Linux,Android)
Re: How can you get the current OS time?
os.date, or os.time, depending on what you need.
https://www.lua.org/pil/22.1.html
Edit: I don't know if these are cross-platform, but I haven't encountered any issues with them. Additionally, the results will conform to the current locale.
https://www.lua.org/pil/22.1.html
Code: Select all
os.time() => 1476852730 -- seconds since epoch
os.date("%X", os.time()) => 00:50:02
os.date("%c", os.time()) => "Wed Oct 19 00:50:02 2016"
Re: How can you get the current OS time?
The timestamp IS platform independent - it counts the number of seconds since a specific point in time (1970),
whereas a 'readable' time string like "00:50:02" or "Wed Oct 19 00:50:02 2016" can be affected by timezone offsets and daylight savings.
whereas a 'readable' time string like "00:50:02" or "Wed Oct 19 00:50:02 2016" can be affected by timezone offsets and daylight savings.
Re: How can you get the current OS time?
Is it possible to write date/time according to ISO 8601? For example date: 2024-09-17 or date and time: 2024-09-17T18:16:00Z
Re: How can you get the current OS time?
Sure.
Code: Select all
print(os.date('%Y-%m-%d')) -- local date
print(os.date('!%Y-%m-%d')) -- zulu date
print(os.date('%Y-%m-%dT%H:%M:%S%z')) -- local time + time offset
print(os.date('!%Y-%m-%dT%H:%M:%SZ')) -- zulu time
Who is online
Users browsing this forum: Google [Bot] and 1 guest