2016-05-11 9 views
1

Ich bin ein Neuling in Velocity. Ich muss ein bestimmtes Datumsformat in ein anderes ändern.Ändern Sie das Datumsformat in Velocity

Eg: Ändern „Mi 11. Mai 12.49.18 JST 2016“ bis „2016.05.11 12.49.18“

Ich fand es eine DateTool ist in VelocityContext aufgenommen werden, um Verwenden Sie $ date.format ("myFormat", myDate), aber es funktioniert nicht. Vielleicht vermisse ich etwas.

Ich fand eine ähnliche Frage, aber ich denke, es ist nicht richtig beantwortet. https://stackoverflow.com/questions/35156429/change-date-format-in-velocity

Vielen Dank im Voraus!

Antwort

1

Ich habe den folgenden Code in VelocityContext Unterklasse:

context.put("date", new DateTool());

und verwendet, um dieses Datum Objekt in meiner .vm-Datei wie folgt:

Order Date : $ctx.date.format('yyyy/MM/dd H:m:s', ${ctx.order.date})

I Link unten genannt:

http://www.java2s.com/Code/Java/Velocity/HowtouseDateinVelocity.htm

+0

Danke für die Freigabe des Links. Es funktioniert gut. –