Andreas Andreas - 4 months ago 52
Java Question

Freemarker model convert timestamp in milliseconds to date

I have a csv-file which i want to transform with fmpp (freemarker). The first column is a long value (milliseconds since 1.1.1970) which i want to convert into a date and format it as datetime.

src format:

1319115474244,40142,Login,200,Login 1-2,text,true,862184,http://localhost:8080/xxx,5378

desirable target format:

20.12.2011 13:45;40142;Login;200;Login 1-2;text;true;862184;http://localhost:8080/xxx;5378

My (running) template:

<#list csv.headers as h>${h}<#if h_has_next>;</#if></#list>
<#list csv as row>
<#list csv.headers as h><#if h_index == 0>Do the date magic<#else>${(row[h]!"N/A")?string}</#if>$<#if h_has_next>;</#if></#list>

For column 0 I want to do the conversion. I DON'T want to write a new model which contains a date. My question is, can this be done in the template without modifying freemarker or fmpp.

any ideas?


FreeMarker 2.3.17 has introduced ?number_to_date, ?number_to_time and ?number_to_datetime for that. See:

You will also want to set the date/time format and zone; see

Mayble you will have to upgrade FreeMarker in FMPP. For that, simply replace the <FMPP_HOME>/lib/freemarker.jar with the latest version.