Sntp.sync() ignores server

烂漫一生 提交于 2019-12-02 11:42:28

The behavior is correct. If you want to work with timezones you need so called "zone files" from the tz database. Each tz file contains (amongst other info) transitions such as daylight saving time, and it also records leap seconds.

There's an example of how to deal with timezones in the NodeMCU repository.

tz = require('tz')
tz.setzone('eastern')
sntp.sync(nil, function(now)
  local tm = rtctime.epoch2cal(now + tz.getoffset(now))
  print(string.format("%04d/%02d/%02d %02d:%02d:%02d", tm["year"], tm["mon"], tm["day"], tm["hour"], tm["min"], tm["sec"]))
end)

So, you need tz.lua plus the zone file(s) for the timezone(s) you're interested in ('eastern' in the example).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!