Forum Discussion
Get current time in UNIX timestamp
- 5 years ago
Try this gutovanzin
= Duration.TotalSeconds(DateTime.LocalNow() - #datetime(1970,1,1,0,0,0))It simply gives you the total seconds from Jan 1, 1970 at midnight through now. Replace my DateTime.LocalNow() with your DateTimeZone.SwitchZone() function and it will work just fine.
You can round that with Number.Round if you don't need all of the decimals.
Try this gutovanzin
= Duration.TotalSeconds(DateTime.LocalNow() - #datetime(1970,1,1,0,0,0))
It simply gives you the total seconds from Jan 1, 1970 at midnight through now. Replace my DateTime.LocalNow() with your DateTimeZone.SwitchZone() function and it will work just fine.
You can round that with Number.Round if you don't need all of the decimals.
- gutovanzin5 years agoFrequent Visitor
Hello!
Thanks for the help, i'm trying to get my timezone, but got this error:= Duration.TotalSeconds(DateTimeZone.SwitchZone(DateTime.LocalNow(),-3) - #datetime(1970,1,1,0,0,0))Expression.Error: We cannot convert the value #datetime(2021, 1, 14, 8, 40, 13.0448086) to type DateTimeZone.
Details:
Value=14/01/2021 08:40:13
Type=[Type]Any suggestion?
Thanks!- edhans5 years agoCommunity Champion
You cannot use DateTime.LocalNow in a timezone function. It doesn't have any timezone data. You need to use DateTimeZone.FixedLocalNow or DateTimeZone.LocalNow.
However, I am not certian you should use any of those anyway. Unix Epoch time is always UTC +0, and when you load this report in the service, DateTime.LocalNow() as I used above also calculate as UTC +0, so it will be apples to apples. Once you get it into Unix Epoch time, then add (3600 * n) seconds to your final answer, where N is your timezone offset.