How to format UTC time to string while taking time zone into account
I have been pondering on this question for a while and cannot come up with a simple solution, while I have the feeling that there absolutely must be one. :-) Here's the situation: I have a template grid where each record represents a different location. The records have a reference to System.TimeZone. What I want to do is show the local time as a string value in each record of the template grid. The TimeZone that the record is referencing should be used to calculate the local time. The result would be that the template grid shows the local time in different time zones from different locations at once in a form for the current DateTime. Does anyone have a tip on how to do this? Is it possible using formatString in any way or do I have to use a Java action?
You can use the time mechanism of Mendix with the following:
Create a dummy user account
Define a calculated attribute which uses the time zone as input.
The corresponding microflow sets the time zone of the dummy user to the requested time zone.
Use the Java action "executeMicroflowAsUser" from CommunityCommons to run a microflow which uses formatDateTime to convert the local time of the user to the string you requested.
The System.TimeZone table was intended to manage user's timezones, there's no feature where it is easy to use this timezone as something to format a time with. However it should be fairly easy to implement in a Java action.
Sebastiaan van den Broek
Perhaps a calculated attribute where the microflow looks at current time, looks at the timezone for the record in question and does that math, returning the time specific to that record?
It describes how you can parse a date with a hardcoded timezone. If you add the timezone as an extra input parameter and replace the hardcoded timezone with the input parameter it should work just as you want it to.