# Find the offset between the Gateway Timezone and the session TimeZoneId

**URL:** <https://forum.inductiveautomation.com/t/find-the-offset-between-the-gateway-timezone-and-the-session-timezoneid/88978>\
**Category:** Ignition\
**Created:** [April 17, 2024, 1:54pm UTC](https://forum.inductiveautomation.com/t/find-the-offset-between-the-gateway-timezone-and-the-session-timezoneid/88978 "2024-04-17T13:54:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kraigen94](https://avatars.discourse-cdn.com/v4/letter/k/919ad9/32.png) [@kraigen94](https://forum.inductiveautomation.com/u/kraigen94)\
**Post date:** [April 17, 2024, 1:54pm UTC](https://forum.inductiveautomation.com/t/find-the-offset-between-the-gateway-timezone-and-the-session-timezoneid/88978/1 "2024-04-17T13:54:40Z")

</div>

Is there a way to get the offset between the Gateway Timezone (UTC) and the timezoneid configured in the session props? What I'm trying to do is to read a json object that has a date as a string, with the time already in the local timezone. However, when I parse it, it gets "converted" to the local timezone. I was thinking I could get the offset between these timezones and add it to the datetime after parsing, but I can find no way to calculate this.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [April 17, 2024, 2:47pm UTC](https://forum.inductiveautomation.com/t/find-the-offset-between-the-gateway-timezone-and-the-session-timezoneid/88978/2 "2024-04-17T14:47:40Z")

</div>

> [@kraigen94](#):
>
> However, when I parse it, it gets "converted" to the local timezone.

Ignition datetime objects are _ **always** _ UTC under the hood, and _ **always** _ converted to some time zone when stringified. If you want parse or stringify in some specific timezone, use java's `ZonedDateTime` and `TimeZone` classes directly, then convert to/from Ignition's `java.util.Date`.

Some reading on this topic:

[https://forum.inductiveautomation.com/search?q=%40pturmel%20ZonedDateTime%20TimeZone%20order%3Alatest](https://forum.inductiveautomation.com/search?q=%40pturmel%20ZonedDateTime%20TimeZone%20order%3Alatest)

In any case, adding or subtracting to a `java.util.Date` object to "correct" its time zone is _ **always** _ a bad idea.

---

<div class="post-metadata">

**Author:** ![kraigen94](https://avatars.discourse-cdn.com/v4/letter/k/919ad9/32.png) [@kraigen94](https://forum.inductiveautomation.com/u/kraigen94)\
**Post date:** [April 17, 2024, 3:49pm UTC](https://forum.inductiveautomation.com/t/find-the-offset-between-the-gateway-timezone-and-the-session-timezoneid/88978/3 "2024-04-17T15:49:08Z")

</div>

I can see why this is a bad idea, what would be a better practice, in your opinion?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [April 17, 2024, 3:52pm UTC](https://forum.inductiveautomation.com/t/find-the-offset-between-the-gateway-timezone-and-the-session-timezoneid/88978/4 "2024-04-17T15:52:08Z")

</div>

> [@pturmel](#):
>
> If you want parse or stringify in some specific timezone, use java's `ZonedDateTime` and `TimeZone` classes directly, then convert to/from Ignition's `java.util.Date`.

Do this.

Do not use strings of dates except when forced to, typically user input and user display. (Perhaps when handling web api traffic, but those typically use unambiguous ISO utc formats.) Everywhere else, work with the UTC-based `java.util.Date` objects.

Wherever you can, let Ignition's components apply a client timezone automatically. Sometimes this requires you to clearly identify datetime objects in ambiguous contexts, like table column rendering.
