Convert Calendar to ISO 8601 Format DateTime String?

一笑奈何 提交于 2019-12-11 10:04:40

问题


I'm trying to output the datePublished field in a Google AMP schema object. For example:

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

The datePublished field in my JCR app is rendering as a FreeMarker Calendar (e.g. Oct 21, 2005 7:00:00 PM) in the template.

How do I convert a data type of Calendar to an ISO 8601 format DateTime string (e.g. 2005-10-22T00:00Z)?


回答1:


Use the FreeMarker string.iso_m_u built-in. For example:

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

Reference: Built-ins for date/time/date-time values



来源:https://stackoverflow.com/questions/57278087/convert-calendar-to-iso-8601-format-datetime-string

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!