Hi,
I don't understand how to use the DzVents methods: UTC, utcSystemTime, utcTime to convert an utc time like 202101132000 to the local time = 202101132100
Somebody could give me an example?
utc to local time [Solved]
Moderator: leecollings
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: utc to local time
There is no ready made method to go from a formatted string representing UTC time to a local time formatted string in dzVents but below example will show you how it can be done.
Code: Select all
-- requires dzVents >= 3.0.17 (domoticz 2020.2 build 12702)
return
{
on =
{
timer =
{
'every minute',
},
},
logging =
{
level = domoticz.LOG_DEBUG,
marker = 'UTC example'
},
execute = function(dz)
local UTCtime = '202101132000'
-- calculate the delta between UTC and local time
local function getTimezone()
local now = os.time()
return math.floor(os.difftime(now, os.time(os.date("!*t", now))))
end
-- Convert the string to an epoch time stamp and add timezone delta in seconds
local myLocalTimestamp = dz.time.dateToTimestamp(UTCtime,'(%d%d%d%d)(%d%d)(%d%d)(%d%d)(%d%d)' ) + getTimezone()
-- Convert the caclulated timestamp to the required format
local localTime = dz.time.timestampToDate(myLocalTimestamp,'yyyymmddhhMM')
dz.log('UTC time ' .. UTCtime .. ' = ' .. localTime .. ' local time', dz.LOG_DEBUG)
end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
hestia
- Posts: 361
- Joined: Monday 25 December 2017 23:06
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2022.1
- Location: Paris
- Contact:
Re: utc to local time [Solved]
Thanks a lot waaren. Again!waaren wrote: Wednesday 13 January 2021 23:08 below example will show you how it can be doneCode: Select all
-- requires dzVents >= 3.0.17 (domoticz 2020.2 build 12702) return { on = { timer = { 'every minute', }, }, logging = { level = domoticz.LOG_DEBUG, marker = 'UTC example' }, execute = function(dz) local UTCtime = '202101132000' -- calculate the delta between UTC and local time local function getTimezone() local now = os.time() return math.floor(os.difftime(now, os.time(os.date("!*t", now)))) end -- Convert the string to an epoch time stamp and add timezone delta in seconds local myLocalTimestamp = dz.time.dateToTimestamp(UTCtime,'(%d%d%d%d)(%d%d)(%d%d)(%d%d)(%d%d)' ) + getTimezone() -- Convert the caclulated timestamp to the required format local localTime = dz.time.timestampToDate(myLocalTimestamp,'yyyymmddhhMM') dz.log('UTC time ' .. UTCtime .. ' = ' .. localTime .. ' local time, dz.LOG_DEBUG) end }
I think there is a typo... I've changed this line:
Code: Select all
dz.log('UTC time ' .. UTCtime .. ' = ' .. localTime .. ' local time, dz.LOG_DEBUG)
Code: Select all
dz.log('UTC time ' .. UTCtime .. ' = local Time ' .. localTime, dz.LOG_DEBUG)- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: utc to local time
Note to my self: Don't do this
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Who is online
Users browsing this forum: No registered users and 1 guest