How to get timestamp (EPOCH)


#1

Hi all, is there any easy way / system variable to get the timestamp in epoch format?

Thanks!
SR.-


#2

have you looked at $now ?


#3

In my environment $now returns 1855491371, which is Wed Oct 18 2028 14:16:11 GMT+0000.

for example $sunrise returns 1/18/2022, 6:01:00 AM. which is correct


#4

That’s strange, mine is coming back with correct date/time. Is the hub location set correctly?

(expression) $now »»» (datetime) 1642534196838
Tuesday, January 18, 2022 12:29:56.838 PM GMT-07:00


#5

As I see, the problem is when I set the value of $now to a type long variable.

If I just print it, it’s fine.


#6

It gets really interesting when you see almost a dozen different ways the same time can be displayed here in webCoRE.


#7

Are you on ST, or HE?


#8

I’m on Smartthings


#9

You could try $localNow or add your timezone offset which you can get from:

round((($localNow-$utc)/3600000.0),0)

This equation creates the difference in hours. I think if you just divide by 1000, you will get the offset you want for your long variable.