5

fmpp(フリーマーカー)で変換したいcsvファイルがあります。最初の列は長い値(1.1.1970からのミリ秒)であり、日付に変換して日時としてフォーマットします。

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を変更せずにテンプレートでこれを実行できるかどうかです。

何か案は?

4

2 に答える 2

26

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、を最新バージョンに置き換えるだけです。

于 2011-10-21T08:41:53.510 に答える
5

私の状況では、これを使用します:

$ {(timeStamp)?number_to_date?string( "yyyy.MM.dd")}

number_to_dateそして、number_to_datetimeまたはに置き換えnumber_to_timeます。

そして、あなたは必要に応じてと交換yyyy.MM.ddすることができYYYY-MM-dd HH:mm:ssます。

これを確認してください:http: //freemarker.org/docs/ref_builtins_expert.html#ref_builtin_numToDate

于 2016-11-09T06:43:13.017 に答える