os.date and os.time

42 views
Skip to first unread message

StUstD

unread,
Jun 19, 2024, 4:07:40 AM (14 days ago) Jun 19
to lu...@googlegroups.com
I'm afraid I'm missing some essential... When I do
```
luajit> os.date("!*t", 0)
---
- sec: 0
  min: 0
  day: 1
  isdst: false
  wday: 5
  yday: 1
  year: 1970
  month: 1
  hour: 0
```
... I obtain the UNIX UTC epoch. However, if I used this data table in os.time, I get.
```
os.time{year=1970,month=1,day=1,hour=0,min=0,sec=0,isdst=false}
---
- -3600
```
... which I had expected should be 0 ....?! (... I also notice that the `isdst` flag makes no difference).
What am I missing? Thanks.
-- Henk

Thijs Schreijer

unread,
Jun 19, 2024, 5:08:44 AM (14 days ago) Jun 19
to lu...@googlegroups.com
Looks like os.time assumes the table to be local-time

try getting the TZ offset (untested):

local tz_offset do
    local now = os.time()
    local utcNow = os.time(os.date("!*t", now))
    tz_offset = os.difftime(now, utcNow)
end

Thijs
Reply all
Reply to author
Forward
0 new messages