且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将纪元转换为日期 &xslt 2.0 中的时区时间

更新时间:2023-02-03 16:58:19

这并不是实际问题的真正答案,即如何获得正确的当地时间,尊重其时区,但我还是把它留在这里,因为它可能对某人有用.

This is not really the answer to the actual question asked, which was how to get the correct local time, respecting its timezone, but I'll still leave it here since it might be usefull to someone.

因为纪元距离 unix 时间只有几秒钟,你可以像这样将它添加到 unix 时间:

Unix 时间是自 1970-01-01 午夜以来经过的秒数,您可以这样做:

Unix time is the number of seconds elapsed since the epoch of midnight 1970-01-01, you can do:

<xsl:value-of select="xs:dateTime('1970-01-01T00:00:00') + xs:dayTimeDuration('PT1212497304S')"
    />

这将为您提供正确的 xs:dateTime 2008-06-03T12:48:24

This will give you the correct xs:dateTime of 2008-06-03T12:48:24

放入一个函数:

<xsl:function name="fn:epochToDate">
    <xsl:param name="epoch"/>
    <xsl:variable name="dayTimeDuration" select="concat('PT',$epoch,'S')"/>
    <xsl:value-of select="xs:dateTime('1970-01-01T00:00:00') + xs:dayTimeDuration($dayTimeDuration)"/>
</xsl:function>