【发布时间】:2019-11-30 00:48:29
【问题描述】:
这两个时间戳似乎在 XSLT 上使用了不同的 GMT。
Timestamp #1
-> 1559780505287
-> 5/6/2019, 9:21:45 PM GMT-3 (dd/mm/yyyy)
Timestamp #2
-> 1562681762005
-> 9/7/2019, 11:16:02 AM GMT-3 (dd/mm/yyyy)
使用在线 xslt 测试工具:https://xslttest.appspot.com/
转换后,时间戳 #1 为 6/6/2019,时间戳 #2 仍为 9/7/2019。 时间戳 #1 应该是 5/6/2019。
如何在 XSLT 上正确使用 GMT-3?
XML:
<java version="1.6.0_45" class="java.beans.XMLDecoder">
<object class="com.MyApp">
<void property="date1">
<object class="java.util.Date">
<long>1559780505287</long>
</object>
</void>
<void property="date2">
<object class="java.util.Date">
<long>1562681762005</long>
</object>
</void>
</object>
</java>
XSLT:
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.w3.org/TR/xhtml1/strict">
<xsl:decimal-format decimal-separator="," grouping-separator="."/>
<xsl:template match="/">
<html>
<head>
<meta charset="utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<meta name="format-detection" content="telephone=no"/>
</head>
<body>
<div class="container">
<h1>Date 1</h1>
<xsl:variable name="date1">
<xsl:value-of select="xs:date('1970-01-01') + java/object/void[@property='date1'] * xs:dayTimeDuration('PT0.001S')"/>
</xsl:variable>
<h2>
<xsl:value-of select="format-date($date1, '[D01]/[M01]/[Y0001]')"/>
</h2>
<h1>Date 2</h1>
<xsl:variable name="date2">
<xsl:value-of select="xs:date('1970-01-01') + java/object/void[@property='date2'] * xs:dayTimeDuration('PT0.001S')"/>
</xsl:variable>
<h2>
<xsl:value-of select="format-date($date2, '[D01]/[M01]/[Y0001]')"/>
</h2>
</div>
</body>
</html>
</xsl:template>
【问题讨论】:
标签: xslt xml-parsing