将dateTime转换为xslt中的unix纪元 [英] Convert dateTime to unix epoch in xslt
本文介绍了将dateTime转换为xslt中的unix纪元的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个dateTime变量,我想把它转换成一个十进制值的历元。
如何做?
I have a dateTime variable, and I want to convert it to a decimal value of epoch. How can this be done?
我尝试使用:
seconds-from-duration($time, xs:dateTime('1970-01-01T00:00:00'))
但它只返回0。
请咨询。
谢谢。
Please advice. Thanks.
推荐答案
此转换:
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xsl:output method="text"/>
<xsl:template match="/">
<xsl:sequence select="current-dateTime()"/>
<xsl:sequence select=
"( current-dateTime() - xs:dateTime('1970-01-01T00:00:00') )
div
xs:dayTimeDuration('PT1S')
"/>
</xsl:template>
</xsl:stylesheet>
当应用于任何XML文档(未使用)时,会生成想要的结果 - 当前日期时间及其Unix纪元(自1970年1月1日以来的秒数):
2010-08-12T06:26:54.273-07:00 1281594414.273
这篇关于将dateTime转换为xslt中的unix纪元的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文