我有一个lastUpdatedAt参数,该参数可以包含以下日期时间格式:
"lastUpdatedAt": "2017-09-09T01:30:42.560"
"lastUpdatedAt": "2019-07-26T13:51:08.000+0100",
"lastUpdatedAt": "2019-07-26T23:58:47+12:00",
"lastUpdatedAt": "2019-03-21T12:35:35Z",
我想要的输出将是以下格式:
"lastUpdatedAt": "2019-07-21T12:47:44.000Z"
我尝试了以下方法,但这当然不适用于所有格式:
<xsl:template match="string[@key='lastUpdatedAt']">
<xsl:variable name="iso-dateTime" select="replace(. ,'^(\d{2})-(\d{2})-(\d{4})\s+(.*)([+-])(\d{2})(\d{2})','$3-$1-$2T$4$5$6:$7')" />
<string key="lastUpdatedAt">
<xsl:value-of select="adjust-dateTime-to-timezone(xs:dateTime($iso-dateTime), xs:dayTimeDuration('PT0H'))"/>
</string>
</xsl:template>
有关如何将这些不同的数据时间格式转换为所需输出的帮助吗?
答案 0 :(得分:1)
我尝试使用
修复可能缺少时区:
分隔符的情况
adjust-dateTime-to-timezone(xs:dateTime(replace(., '(\+|-)([0-9]{2})([0-9]{2})$', '$1$2:$3')), xs:dayTimeDuration('PT0H'))
然后我得到的结果是2017-09-09T01:30:42.56Z 2019-07-26T12:51:08Z 2019-07-26T11:58:47Z 2019-03-21T12:35:35Z
:https://xsltfiddle.liberty-development.net/pPzifqp
因此,在模板匹配单个值的情况下,您可以使用
<xsl:template match="string[@key='lastUpdatedAt']">
<string key="lastUpdatedAt">
<xsl:value-of select="adjust-dateTime-to-timezone(xs:dateTime(replace(., '(\+|-)([0-9]{2})([0-9]{2})$', '$1$2:$3')), xs:dayTimeDuration('PT0H'))"/>
</string>
</xsl:template>