首页 > 解决方案 > 如何像javascript日期函数一样在xslt格式中将字符串数字转换为日期?

问题描述

嗨如何在xslt中将字符串数字转换为日期格式

我的代码是

<insertdate>1494489190000</insertdate>

我在谷歌找到了很多次,但没有找到任何好的解决方案,请建议我们什么是最好的解决方案。

像这样在做javascript

new Date(1494489190000)
Thu May 11 2017 13:23:10 GMT+0530 (India Standard Time)

但是如何在 xslt 中做。

标签: htmlxmlxslt

解决方案


我认为在 JavaScript 中Date,对于 XSLT/XPath 2 及更高版本,构造函数自 1970 年 1 月 1 日以来的毫秒数,xs:date或者xs:dateTime您需要采用该日期并将值添加为持续时间:

  <xsl:param name="date-time-value" as="xs:integer" select="1494489190000"/>

  <xsl:variable name="dateTime" as="xs:dateTime"
    select="xs:dateTime('1970-01-01T00:00:00') + xs:dayTimeDuration('PT' || $date-time-value div 1000 || 'S')"/>

format-date使用or可以使用不同的输出格式,从http://www.datypic.com/books/xquery/chapter20.htmlformat-dateTime中的示例开始,然后查看规范https://www.w3.org/TR/xpath- functions/#func-format-dateTimehttps://www.w3.org/TR/xpath-functions/#rules-for-datetime-formatting或就您取得的成果提出具体问题。


推荐阅读