Search code examples
datetimelocalefreemarker

Freemarker datetime for different locales


I have following code,

<#assign dateAndtime = "2020-08-17T16:08:31.496Z"?datetime.iso?string("yyyy年MM月dd日(E) HH:mm")>  
${dateAndtime}

output is 2020年08月17日(Mon) 21:38

I want to print like "2020year08month17day (Mon) 21:38". What should i pass instead of "yyyy年MM月dd日(E) HH:mm"

I can get the year, month and date separetely and then append with "year","month"and "day" strings respectively to get like 2020year08month17day (Mon) 21:38". But i dont want to do that. Is there any other way to acheive this?

TIA


Solution

  • You can use:

    <#assign dateAndtime = "2020-08-17T16:08:31.496Z"?datetime.iso?string["yyyy'year'MM'month'dd'day'(E) HH:mm"]>
    ${dateAndtime}
    

    The date format used is the one from java's SimpleDateFormat.