[Excel Exporter] Date/Time attribute is in different Time Zone

0
Hi, I am using the below Excel Exporter to export a report but the Date/Time attribute in the exported excel file does not follow the correct time zone. It works when I test it locally on my PC. But after we deploy it to the Production server and the scheduled event is triggered, the data appears different for the date time attribute. It seems that the contents of the excel file is determined by the We are using Mendix 8.12.0 Regards Kevin  
asked
2 answers
1

Date time, always a pain in the @$$

Take a look at this learning path for more background on how DateTimes are handled

answered
0

I have this issue too and a quick search on the forum learns that many people face this issue. For example see https://forum.mendix.com/link/questions/95717. I think the only solution is to add a text attribute and keep a textual copy of the DateTime value there. You can use formatDateTime for that if you are sure that the microflow is executed by a user in the right time zone, otherwise you can use a java action for that.

The java code that I use is:

TimeZone tz = TimeZone.getTimeZone(timeZone);
SimpleDateFormat sdf = new SimpleDateFormat(pattern);
sdf.setTimeZone(tz);
String result = sdf.format(date);

I embedded this code in a java action "FormatDateTimeWithTimeZone” with parameters:

  • date (DateTime)
  • timeZone (string) (Time zone ID, a full name such as "America/Los_Angeles", "Europe/Amsterdam". See https://garygregory.wordpress.com/2013/06/18/what-are-the-java-timezone-ids/)
  • pattern (string)
answered