【发布时间】:2018-10-27 14:15:41
【问题描述】:
我想将 Instant 时间转换为 Date,但出现此错误:
freemarker.template.TemplateException:预期的哈希值。 newDate 被评估为 freemarker.template.SimpleDate
我在 Java 上这样做:
Date newDate = new Date();
Instant instant = Instant.now();
webContext.put("newDate",new Date());
webContext.put("instant",instant);
我正在 Freemarker 上这样做:
[#assign dateFormated = newDate.getAsDate().from(instant.ofEpochSecond(data.time.seconds))/]
谢谢
【问题讨论】:
-
你的意思是
Date newDate = Date.from(Instant.now()); -
@YCF_L mm 不,我这样做是为了初始化变量,在 Freemarker 中可以执行 newDate.getAsDate().from(instant.ofEpochSecond(data.time.seconds))
-
用我的解决方案我想你只需要
[#assign dateFormated = newDate/]我不熟悉freemaker -
@YCF_L 我不能这样做,因为在 Freemarker 上我为每个数据做一个 for 并获取日期,所以我不能将 Java 上的每个日期传递给 freemarker,我可以,但那不是为我工作
-
嗯,对不起,我不知道
标签: java date freemarker