我有一个csv文件,我想用fmpp(freemarker)进行转换。第一列是一个长值(自1970年1月1日起以毫秒为单位),我想将其转换为日期并将其格式化为datetime。

src格式:

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

理想的目标格式:
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

我的(运行中)模板:
<#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>

对于第0列,我想进行转换。我不想编写一个包含日期的新模型。我的问题是,可以在模板中完成此操作而无需修改freemarker或fmpp。

有任何想法吗?

最佳答案

FreeMarker 2.3.17为此引入了?number_to_date?number_to_time?number_to_datetime。另请:http://freemarker.org/docs/ref_builtins_expert.html#ref_builtin_numToDate

您还将需要设置日期/时间格式和区域;见http://fmpp.sourceforge.net/settings.html#sect17

可能您将必须在FMPP中升级FreeMarker。为此,只需将<FMPP_HOME>/lib/freemarker.jar替换为最新版本即可。

关于java - Freemarker模型将时间戳转换为毫秒,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7846105/

10-14 11:28