将日历转换为ISO 8601格式的DateTime字符串?

时间:2019-07-30 18:34:14

标签: freemarker

我正在尝试在Google AMP schema object中输出datePublished字段。例如:

<script type="application/ld+json">
  {
      ...
      "datePublished": "2005-10-22T00:00Z",
      ...
  }
</script>

我的JCR应用程序中的datePublished字段在模板中呈现为FreeMarker Calendar(例如Oct 21, 2005 7:00:00 PM)。

如何将Calendar的数据类型转换为ISO 8601格式的DateTime字符串(例如2005-10-22T00:00Z)?

1 个答案:

答案 0 :(得分:1)

使用内置的FreeMarker string.iso_m_u。例如:

<script type="application/ld+json">
  {
      ...
      "datePublished": "${publishDate!?string.iso_m_u}",
      ...
  }
</script>

参考:Built-ins for date/time/date-time values

相关问题