本文介绍了dateTime 到 Epoch,反之亦然 xslt的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试将给定的日期时间转换为纪元时间,并将给定的纪元时间转换为日期时间.我对 xslt 很陌生,并且已经为此苦苦挣扎了一段时间,它没有给我任何结果.到目前为止,这是我的 xslt

I have been trying to convert a given dateTime to epoch time and also a given epoch time to dateTime. I am quite new to xslt and have been struggling with this quite for some time, it is not giving me back any results. Here is my xslt so far

    <xsl:stylesheet version="1.0"
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xmlns:ns0="http://www.NoPreAuth.org"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                exclude-result-prefixes="xsi xsl ns0 xsd">
<xsl:template match="/">
<xsl:variable name="date1">
        <xsl:value-of select="/ns0:NoAuthInput/ns0:StartDate"/>
</xsl:variable>
<xsl:variable name="date2">
        <xsl:value-of select="/ns0:NoAuthInput/ns0:EndDate"/>
</xsl:variable>
<ns0:NoPreAuthInput>
<ns0:Product>
        <xsl:value-of select="/ns0:NoAuthInput/ns0:Product"/>
</ns0:Product>
<!-- datTime to epoch -->
<ns0:END_T>
  <xsl:value-of select= "(('$date1')  - xsd:dateTime('1970-01-01T00:00:00') )  div  xsd:dayTimeDuration('PT1S') "/>
</ns0:END_T>
<!-- epoch To datTime -->
<ns0:Closed_T>
  <xsl:value-of select= "(('$date2')  + xsd:dateTime('1970-01-01T00:00:00') )  *  xsd:dayTimeDuration('PT1S') "/>
</ns0:Closed_T>
</ns0:NoPreAuthInput>
</xsl:template>
</xsl:stylesheet>

而我要转换的 xml 是:

and the xml which I am trying to convert is:

<?xml version="1.0" encoding="UTF-8" ?>
<NoAuthInput xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.NoAuth.org

 xmlns="http://www.NoAuth.org">
   <Product>ABC</Product>
   <StartDate>2015-10-05T15:52:40.782</StartDate>
   <EndDate>1444150760</EndDate>
</NoAuthInput>

对此的任何帮助都非常感谢.谢谢

any help on this much appreciated. Thanks

推荐答案

转换 Unix 时间到 ISO 8601 日期时间:

To convert Unix time to ISO 8601 date-time:

<xsl:value-of select="xs:dateTime('1970-01-01T00:00:00') + xs:dayTimeDuration(concat('PT', UnixTime, 'S'))"/>

ISO 8601 日期时间 转换为 Unix 时间;

To convert ISO 8601 date-time to Unix time;

<xsl:value-of select="floor((xs:dateTime(ISODateTime) - xs:dateTime('1970-01-01T00:00:00')) div xs:dayTimeDuration('PT1S')) "/>

需要 XSLT 2.0.

Requires XSLT 2.0.

工作演示:http://xsltransform.net/94rmq5L

这篇关于dateTime 到 Epoch,反之亦然 xslt的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 14:14