ht_3535
ht_3535

Reputation: 373

Freemarker ISO string to datetime with timezone

I need to display the below "String" in the desired format

String str = 1979-01-24T00:00:00.000-08:00
Desired format: Jan 24, 1979 00:00:00 AM PST

Note: The tz in the str could be any tz not limited to PST.
Tried the below but none worked:

Upvotes: 1

Views: 1846

Answers (2)

ddekany
ddekany

Reputation: 31152

The problem here is that FreeMarker parses date/time values to java.util.Date (and its subclasses), which don't store a time zone anymore, as it always stores the value in UTC. So that information is lost after parsing. As of 2.3.30, the only solution I see to do this in Java (with Java 8 ZonedDateTime).

Upvotes: 1

Shihaocat
Shihaocat

Reputation: 56

The timezone can be configured by the following setting, as refer to their documentation https://freemarker.apache.org/docs/ref_directive_setting.html

<#setting time_zone ="PST">
<#assign str = "1979-01-24T00:00:00.000-08:00">
${str?datetime.iso}

Upvotes: 1

Related Questions