I need to display times in two different time zones.
The following works, but the formatting for the Chicago time is ugly:
<p><b>Report performed (Belfast): </b> ${.now?string["EEEE, MMMM dd, yyyy, hh:mm a '('zzz')'"]}</p>
<p><b>Report performed (Chicago): </b> ${.now?iso('America/Chicago')}</p>
Results:
Report performed (UTC): Apr 23, 2019 12:08:27 PM
Report performed (Chicago): 2019-04-23T06:08:27-05:00
Attempting to concatenate results in an error:
<p><b>Report performed (Chicago): </b> ${.now?iso('America/Chicago')?string["EEEE, MMMM dd, yyyy, hh:mm a '('zzz')'"]}</p>
12:30:18.307 [main] ERROR freemarker.runtime - Error executing FreeMarker template
freemarker.core.NonHashException: For "...[...]" left-hand operand: Expected a hash, but this has evaluated to a string (wrapper: f.t.SimpleScalar): ==> .now?iso('America/Chicago')?string [in template "emailTemplate.ftl" at line 80, column 54]
FTL stack trace ("~" means nesting-related):
at freemarker.core.DynamicKeyName.dealWithStringKey(DynamicKeyName.java:142) ~[freemarker-2.3.25-incubating.jar:2.3.25]
at freemarker.core.DynamicKeyName._eval(DynamicKeyName.java:75) ~[freemarker-2.3.25-incubating.jar:2.3.25]
at freemarker.core.Expression.eval(Expression.java:81) ~[freemarker-2.3.25-incubating.jar:2.3.25]
at freemarker.core.DollarVariable.calculateInterpolatedStringOrMarkup(DollarVariable.java:96) ~[freemarker-2.3.25-incubating.jar:2.3.25]
at freemarker.core.DollarVariable.accept(DollarVariable.java:59) ~[freemarker-2.3.25-incubating.jar:2.3.25]
at freemarker.core.Environment.visit(Environment.java:327) [freemarker-2.3.25-incubating.jar:2.3.25]
at freemarker.core.Environment.visit(Environment.java:333) [freemarker-2.3.25-incubating.jar:2.3.25]
at freemarker.core.Environment.process(Environment.java:306) [freemarker-2.3.25-incubating.jar:2.3.25]
at freemarker.template.Template.process(Template.java:386) [freemarker-2.3.25-incubating.jar:2.3.25]
at mycode...
I believe You can't do it with one go because .iso
or any dateformat it will return string . by default you can specify time_zone in the ftl and do dateformat.
<#setting time_zone="America/Chicago">
<#assign aDateTime = .now>
${aDateTime?string["EEEE, MMMM dd, yyyy, hh:mm a '('zzz')'"]}
It giving output Tuesday, April 23, 2019, 07:35 AM (CDT)
For further reference Please look at this Document