Forum Discussion
Hey @Kien,
If you ever come across a use case where you need to add or remove hours from a certain datetime, there are functions specifically for doing that:
Date.now().plusHours(5)
Date.now().minusHours(5)
But as you said, in this case that would mean hardcoding the time difference.
That’s why you can do this by calculating the difference between EST and GMT which will take daylight saving into consideration, and from there you can manipulate the result by adding or removing hours to adjust the required difference.
Date.now().toLocaleDateTimeString({timeZone:"EST", format: "HH"}) - Date.now().toLocaleDateTimeString({timeZone:"GMT", format: "HH"}) -1
This expression will return -5 hours difference, which will be - 4 during daylight saving.
I hope you’ll find this helpful,
Regards,
Bojan.
Instead of using EST/EDT, you could use the Joda time zone alias, in this case "US/Eastern"
, to have the expression handle the offset automatically depending on the date.