Created
April 11, 2017 10:06
-
-
Save planetsizebrain/a9dc41e72f3fba2a1bd84caef0741ac5 to your computer and use it in GitHub Desktop.
Liferay Freemarker datetime format with 4-digit year
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<#setting time_zone=timeZone.ID> | |
<#setting locale=locale.toString()> | |
<#setting datetime_format="MM/dd/yyyy"> | |
<ul> | |
<#list entries as entry> | |
<li><li>${entry.title} - ${entry.modifiedDate?datetime}</li></li> | |
</#list> | |
</ul> |
OK, now I understand what you want to achieve. In that case I think you might need to use conditional construction that sets the datetime_format according to the current portal locale.
<#setting time_zone=timeZone.ID>
<#setting locale=locale.toString()>
<#assign portalLocale=locale.toString()>
<#if portalLocale="en_US">
<#setting datetime_format="MM/dd/yyyy">
<#else>
<#setting datetime_format="dd/MM/yyyy">
</#if>
${.now?datetime}
Ok, not very confortable if I have to manage a portal supporting 30 different languages, but I got the point.
Thank you!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This snippet makes sense only if you have en_EN or en_US locale: this way english users will see dates in format MM/dd/yyyy, as they expect.
Here, if I change my portal language to italian and so my locale becomes it_IT, the datetime format remains MM/dd/yyyy because it is forced on that format at line 3.
But this is not the desired behaviour: if locale is it_IT, I should see a dd/MM/yyyy format instead.
Is there a way to solve this?
Thank you