How to format UTC time to string while taking time zone into account

0
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?
asked
5 answers
2

How about a calculated date/time attribute like

addMinutes([%CurrentDateTime%], round($TimeZone/RawOffset:60000))

answered
1

You can use the time mechanism of Mendix with the following:

  1. Create a dummy user account
  2. Define a calculated attribute which uses the time zone as input.
  3. The corresponding microflow sets the time zone of the dummy user to the requested time zone.
  4. 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.
answered
0

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.

answered
0

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?

answered
0

You should have a look at this question

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.

answered