Lua Time variable

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 !

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")

Forgot to mention I trying that within pleg…
I tried local t = os.date “%Hh%M” but it fail…

Perhaps the pushover call is incorrect somehow?

Nope, its working with pushover with the code I showed but not with "local t = os.date “%Hh%M” :frowning:
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.

[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