vendredi 9 janvier 2015

How to convert date in specific format in Freemarker template or javascript


From json, i am getting the value as



"createdOn": "Jan 08 2015 20:40:56 GMT+0530 (IST)",


I am Accessing in FTL



<#list variables as variable>
<div class="reply">
${variable.createdOn}
</div>
</#list>


The result i am getting is



Jan 09 2015 12:36:18 GMT+0530 (IST)


My preferable format is 09-01-2015


I need to remove rest of the time GMT, IST and so on.


How to convert this in Freemarker template or javascript.


Update


I tried to pass below like this



${variable.createdOn?datetime?string("dd-MM-yyyy")}


but it is giving error as



Exception: java.text.ParseException - Unparseable date: "Jan 09 2015 12:36:18 GMT+0530 (IST)"


Any help is Appreciated.


Thanks





1 commentaire:

  1. Please check the answer here

    http://stackoverflow.com/questions/27857058/how-to-convert-date-in-specific-format-in-freemarker-template-or-javascript/27866821#27866821


    <#setting date_format="dd-MM-yyyy">
    <#setting locale="en_US">
    <#assign createdOn = variable.createdOn>
    ${createdOn?datetime("MMM dd yyyy HH:mm:ss 'GMT'Z")?date}

    RépondreSupprimer