Installing pytz library

Then you cannot rely on Ignition to automatically handle this for you. You should still always record and transfer timestamps in UTC.

Provide your users with some timezone session custom property, or pass the appropriate timezone id's as part of your machine information, but keep track of what timezone you need at any point in your GUI. Then use the techniques in this post to display timestamps in any desired timezone (instead of session.props.timezoneId):

1 Like

Thank you Phil for your patience, the link is very useful.. tomorrow I will study it with calm and I will update this topic.

Have a nice day, and thanks again

Hello everyone, at the moment I'm using @pturmel function to return the ZoneId datetime and it works very good for my needs.

I modify the return in this way so to have a datetime datatype:

return ts.toInstant().atZone(ZoneId.of(zoneid)).format(formatter)
return system.date.parse(ts.toInstant().atZone(ZoneId.of(zoneid)).format(formatter), "yyyy-MM-dd HH:mm:ss")

is this ok or is better to manage in another way?

The first one should return a string, not a datetime.

Where are you using this and what are you trying to achieve with it ?

What exactly is the input to this ? A unix timestamp ?
If that's the case, system.date.fromMillis() will convert it into a datetime object.

Yes the first one is the "original" that return the string, I modify the second to have a datetime.

I need to have a datetime conversion accordly to the timezone.

In this case the input is system.date.now()

I think you're missing an important point in Phil's advice: keep the datetime as UTC and only convert where you need to display it.
Pass the original datetime returned by your database, which should be UTC if you listened to Phil, do the things you need to do with it, and then, as a last operation before it's displayed, convert it to a string, using whatever timezone should be used for this particular date.

1 Like

At the moment I need to write in the DB the values with the timezone not in UTC because I have to continue with the same standard as is still working in this moment.

The same advice applies, except you'll use the zonedFormat function Phil provided when you need to display the date. You'll just have to keep track of what zone the date is in, which pretty much means "retrieve it from the db when pulling the data, and pass it along whenever you're passing the datetime"

1 Like

Thanks for the expanation, I'll work on the zonedFormat function, thank you for the help