Displaying current times in 2 Time Zones

Hi All.

I am in Melbourne, Australia. We are currently in Australian Eastern Daylight Time, AEDT, which is currently UTC+11.

While Brisbane, Australia is in the Australian Eastern Standard Time (AEST), which is UTC +10.

In a couple of days AEDT will be over and we will fall back to AEST.

Now, I need to display current date/time in both Melbourne and Brisbane. Displaying local time is fine. But displaying Brisbane time is giving me grief.

I tried addHours(now(),10) but the string is converted to local time automatically.

How can I display Brisbane AEST time? Is there an Ignition method?

Thanks.

What component are you displaying this in? addHours returns a date, not a string.

1 Like

Don't do arithmetic on the date object. Use manual formatting for a desired time zone, as described here:

Ignition datetime objects are instances of java.util.Date, and are fundamentally UTC. That is, they have no timezone of their own, but display in whatever time zone the JVM is using. That means they can be sent across a network and remain true to the instant in global time with which they were created, regardless of time zone.

The implication is that you should always think about these objects as UTC. Another, more elaborate discussion:

3 Likes

Hi Justin.
Yup, agreed. The returned date from the expression addHours(now(), 10) is written to a tag. So, the tag gets a string representation of the date object.

Thanks pturmel.

Dear All,

For anyone interested, here's what I have done:

  • followed pturmel's posts given above.
  • massaged the example script to read current time, convert it to required time zone, format it and write the object into a string tag.
  • Added a script in the Project Library
  • From the Gateway Events, called the script every minute

This is working fine, so far.