html - 如何像javascript日期函数一样在xslt格式中将字符串数字转换为日期?
问题描述
嗨如何在xslt中将字符串数字转换为日期格式
我的代码是
<insertdate>1494489190000</insertdate>
我在谷歌找到了很多次,但没有找到任何好的解决方案,请建议我们什么是最好的解决方案。
像这样在做javascript
new Date(1494489190000)
Thu May 11 2017 13:23:10 GMT+0530 (India Standard Time)
但是如何在 xslt 中做。
解决方案
我认为在 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-dateTime,https://www.w3.org/TR/xpath-functions/#rules-for-datetime-formatting或就您取得的成果提出具体问题。
推荐阅读
- azure - API“订阅 - 创建” - 需要哪个范围?
- flutter - 如何在运行时对 Flame (Flutter) 中精灵的渲染顺序进行排序?
- testing - 如何在 TFS 中编辑测试用例
- jenkins - 如何从标签链接作业中读取数据| 使用 groovy 脚本的 Jenkins 插件
- c# - 后台任务 - 即使应用程序已停止,如何在 .net Web 应用程序上运行后台任务?
- ios - 如何获取具有最高 Int 的变量并检索 String Swift
- html - HTML 选择一个 zip 文件或多个其他文件
- java - 错误:更新到 Android Studio 北极狐后,在视图中找不到符号导入 android.widget.set | 2020.3.1 补丁 2
- java - 百里香中的标签库
- vue.js - 在渲染期间访问了属性“dynamicslotname”,但未在实例上定义