Tlex
November 27, 2018, 4:06pm
#1
Good day,
I’m trying to display the current time via pushover and it works but I have issues when the minutes only have one digits. Let say it’s 14h02, the system will return 14h2. Is their a better way I could do that ?
hours = os.date(‘*t’,os.time())[“hour”]
minutes = os.date(‘*t’,os.time())[“min”]
pushover ("Door open at ",hours … “:” … minutes, “1”, " ", " ", “Gamelan”)
Thanks for your help !
akbooer
November 27, 2018, 4:12pm
#2
Yes, absolutely. The system function os.date() can do all you need:
local t = os.date "%Hh%M"
print(t)
will produce (just now, on my system):
16h08
So I imagine that this should work:
local t = os.date "%Hh%M"
pushover ("Door open at ",t, "1", " ", " ", "Gamelan")
Tlex
November 27, 2018, 4:33pm
#3
Forgot to mention I trying that within pleg…
I tried local t = os.date “%Hh%M” but it fail…
akbooer
November 27, 2018, 4:43pm
#4
Perhaps the pushover call is incorrect somehow?
Tlex
November 28, 2018, 12:10am
#5
Nope, its working with pushover with the code I showed but not with "local t = os.date “%Hh%M”
maybe thats something with pleg…
I think it is. I do not use PLEG and am pushing all my notifications through pushover and for me it is working.
ZW-Tom
January 5, 2019, 4:17am
#7
[quote=“Tlex, post:1, topic:200139”]Good day,
I’m trying to display the current time via pushover and it works but I have issues when the minutes only have one digits. Let say it’s 14h02, the system will return 14h2. Is their a better way I could do that ?
hours = os.date(‘*t’,os.time())[“hour”]
minutes = os.date(‘*t’,os.time())[“min”]
pushover ("Door open at ",hours … “:” … minutes, “1”, " ", " ", “Gamelan”)
Thanks for your help ![/quote]
Try this:
local minNum = tonumber(t.min)
if minNum <= 9 then
minStr = tostring(minNum)
minStr = “0” … minStr
else
minStr = t.min
end
Hope that helps.
Tom