问题
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