【问题标题】:Change the date format in Velocity在 Velocity 中更改日期格式
【发布时间】:2016-05-11 05:09:39
【问题描述】:

我是 Velocity 的新手。我需要将某种日期格式更改为另一种。

例如:将“2016 年 5 月 11 日星期三 12:49:18 JST”更改为“2016/05/11 12:49:18”

我发现有一个 DateTool 包含在 VelocityContext 中以便使用 $date.format("myFormat", myDate),但它不起作用。可能是我错过了什么。

我发现了一个类似的问题,但我认为它没有正确回答。 https://stackoverflow.com/questions/35156429/change-date-format-in-velocity

提前致谢!

【问题讨论】:

    标签: velocity date-format


    【解决方案1】:

    我在 VelocityContext 子类中添加了以下代码:

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

    并在我的 .vm 文件中使用此日期对象,如下所示:

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

    我参考了以下链接:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-10-12
      • 2013-06-03
      • 2015-03-03
      • 2011-11-18
      • 2022-01-28
      • 2014-10-23
      • 2016-11-18
      • 1970-01-01
      相关资源
      最近更新 更多