Convert Unix time to readable time 24h format?

I Apologise on beforehand… despite some googling and searching on this forum I cannot find how to convert unix time stamp to a readable time (24h format so 14:45:15 as example) in an expression.
I tried (amongst others): os.time(’%T’,StartRain) where StartRain is an expression variable converted to a number.
Concrete example: 1627167900 should be converted to 01:05:00
(in my time zone Netherlands = GMT+02:00)

Who can help me ?

I assume you mean doing this in a Reactor expression? Using os.time() won’t work, because Reactor expressions are not Lua. In your other post (exponents), I gave you a link to the documentation, and from the docs for expressions, you’ll find links to LuaXP’s general expression syntax and built-in function library (LuaXP is the expression evaluator library that Reactor uses). Use the strftime() function to convert a Unix timestamp to a human-readable date/time.

1 Like

@rigpapa: your assumption is right. I went through your documentation already (very well done!) but missed the links to LuaXP.
Now I succeeded. I also used another string function sub(s,i,j).
For other users: I use a Reactor Sensor to retrieve data from a weather API (only Dutch “Buienradar”) for predicted rainshowers. It gives a warning notification (in seconds before the rainshower starts), the predicted rainintensity and also the starttime and stoptime of the rainshower. These times are in Unix timestamp and I converted these in 24h readable times.
I use the sub function to skip the seconds (because they are always “00”).

StartRain = tonumber(getstate( 1105, “urn:brutgrink-com:serviceId:dutchRainAlarm”, “StartRain” )) gives 1627241100

StarttijdRegen = sub((strftime("%X",StartRain)),1,5) gives “21:25”

Within an hour I know if the prediction was correct :grinning:

Best Home Automation shopping experience. Shop at getvera!

© 2021 Ezlo Innovation, All Rights Reserved. Terms of Use | Privacy Policy | Forum Rules