I have an XML document that has dates in standard ISO 8601 format. Like this:
2011-11-29T04:15:22-08:00
I would like to convert the time to UTC and the output date in the following form using XSLT:
2011-11-29 12:15:22
How can it be done?
Thanks in advance.
The following XPath 2.0 expression produces the wanted string value:
translate(
string(
adjust-dateTime-to-timezone(
xs:dateTime('2011-11-29T04:15:22-08:00'),
xs:dayTimeDuration('PT0H')
)
),
'TZ',
' '
)
XSLT - based verification:
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="/">
<xsl:sequence select=
"translate(
string(
adjust-dateTime-to-timezone(
xs:dateTime('2011-11-29T04:15:22-08:00'),
xs:dayTimeDuration('PT0H')
)
),
'TZ',
' '
)
"/>
</xsl:template>
</xsl:stylesheet>
when this transformation is applied on any XML document (not used), the XPath expression is evaluated and the result of this evaluation is output:
2011-11-29 12:15:22
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With