I'm using Freemarker Version 2.3.20.
I have a data structure where two dates are contained - one in local time and one in utc time.
// 2017-07-17 18:30 UTC
ZonedDateTime utcTime = ZonedDateTime.of(2017, 7, 17, 18, 30, 0, 0, ZoneId.of("UTC"));
// 2017-07-17 20:30 (+02:00)
ZonedDateTime localTime = utcTime.withZoneSameInstant(ZoneId.of("Europe/Berlin"));
Freemarker can handle only java.util.Date so I'm handing over dates.
Map<String, Object> mapping = new HashMap<String, Object>();
mapping.put("departureTimeLocal", Date.from(localTime.toInstant()));
mapping.put("departureTimeUtc", Date.from(utcTime.toInstant()));
In my template I would expect to write something like:
Departure (local): ${departureTimeLocal?string['HH:mm']}
Departure (UTC) : ${departureTimeUtc?string['HH:mm']}
And as a result I would like to see:
Departure (local): 20:30
Departure (UTC) : 18:30
What I see currently is:
Departure (local): 20:30
Departure (UTC) : 20:30 <#-- timestamp interpreted in local time -->
I've also tried something like:
Departure (converted): ${(departureTimeLocal?string['yyyy-MM-dd HH:mm'] + ' UTC')?datetime['yyyy-MM-dd HH:mm z']?string['HH:mm']}
--> Departure (converted): 22:30
What would be the best way to archive something like that?
Yes I know: java.util.Date does not really have a timezone (only for printing) and localTime/utcTime.toInstant() both map to the same instants in zulu time.