Time functions
Posted:
Tue Feb 02, 2016 10:13 pm
by cwilt
I have a custom build which includes sntp and rtctime modules. Now I can set time based on the return for NTP server.
For the life of me I am unable to find any time functions. Anyone else playing with these functions find a way to display time and date?
Re: Time functions
Posted:
Thu Feb 04, 2016 2:49 pm
by devsaurus
I use the following simple code to output time:
Code: Select allfunction hr_min_sec(stamp)
return stamp % 86400 / 3600, stamp % 3600 / 60, stamp % 60
end
function show_time()
local stamp
local tz = 2
stamp = rtctime.get() - 1104494400 - 1104494400 + tz*3600
return(string.format("%02u:%02u:%02u", hr_min_sec(stamp)))
end
Displaying the date would need similar arithmetic but I never did it myself.
Re: Time functions
Posted:
Thu Feb 04, 2016 10:19 pm
by cwilt
Thanks.
I had started writing my own functions to handle date and time. Your method is very simple. I like it.
Wonder how the date would work...