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:
timeStamp,elapsed,label,responseCode,threadName,dataType,success,bytes,URL,Latency
1319115474244,40142,Login,200,Login 1-2,text,true,862184,http://localhost:8080/xxx,5378
desirable target format:
timeStamp;elapsed;label;responseCode;threadName;dataType;success;bytes;URL;Latency
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>
</#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: http://freemarker.org/docs/ref_builtins_expert.html#ref_builtin_numToDate
You will also want to set the date/time format and zone; see http://fmpp.sourceforge.net/settings.html#sect17
Mayble you will have to upgrade FreeMarker in FMPP. For that, simply replace the <FMPP_HOME>/lib/freemarker.jar
with the latest version.
In my situation, I use this:
${(timeStamp)?number_to_date?string("yyyy.MM.dd")}
And replace number_to_date
with number_to_datetime
or number_to_time
;
And you can replace yyyy.MM.dd
with YYYY-MM-dd HH:mm:ss
as you need.
check this: http://freemarker.org/docs/ref_builtins_expert.html#ref_builtin_numToDate
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With