2016-05-11 38 views
1

我是Velocity的新手。我需要將某個日期格式更改爲另一個日期格式。更改速度中的日期格式

如:改變「週三5月11日12點49分十八秒JST 2016」到「2016年5月11日12點49分十八秒」

我發現有被列入VelocityContext爲了一個DateTool使用$ date.format(「myFormat」,myDate),但它不起作用。可能是我錯過了一些東西。

我發現了一個類似的問題,但我認爲它沒有正確回答。 https://stackoverflow.com/questions/35156429/change-date-format-in-velocity

在此先感謝!

回答

1

我加入VelocityContext子類以下代碼:

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

在我.vm文件中像這樣使用這個日期對象:

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

我稱爲鏈接如下:

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

+0

感謝您分享此鏈接。它工作正常。 –