Reputation: 6570
I am trying to get New York time (which is different than my local time) by following code in Lua:
local utc_t = os.date("!*t", os.time())
local tzoffset = -1 * 5 * 60 * 60 -- EST is -05:00 from UTC
local est_t = os.date("*t", os.time(utc_t) + tzoffset)
However, for New York, there is daylight saving time (& the dates to enter/exit daylight saving time are different each year).
When it's in daylight saving time, it's EDT (-04:00 from UTC).
Is there any way I can get the correct New York time at any given time in any local timezone?
Upvotes: 4
Views: 1174
Reputation: 2364
Use the luatz
library. Specifically, use the function time_in(timezone_name)
.
You can either install it as a rock or grab the source. See https://rocks.moonscript.org/modules/daurnimator/luatz for further information.
Upvotes: 2