2016-05-11 37 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

感谢您分享此链接。它工作正常。 –