将纪元转换为日期 &xslt 2.0 中的时区时间 [英] Converting epoch to date & time with time zone in xslt 2.0

查看:47
本文介绍了将纪元转换为日期 &xslt 2.0 中的时区时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将纪元时间转换为日期&时间基于 xslt 2.0 中的时区?

How do I convert epoch time to date & time based on time zone in xslt 2.0 ?

例如纪元时间 1212497304 转换为

For example, epoch time 1212497304 converts to

格林威治标准时间:2008 年 6 月 3 日星期二 12:48:24 GMT时区:martes,2008 年 3 月 3 日 14:48:24 GMT+2

GMT: Tue, 03 Jun 2008 12:48:24 GMT time zone: martes, 03 de junio de 2008 14:48:24 GMT+2

这是因为夏令时 (DST):在许多国家/地区,夏季多出一小时,在某些日期每年都会有所不同.

This is because of the Daylight Saving Time (DST): in many countries there is one hour more in summer, during some dates that varies each year.

例如,假设这条指令:

<xsl:value-of select=" format-dateTime(xs:dateTime('2013-07-07T23:08:00+00:00'), '[D] [MNn] [Y] [h]:[m01][PN,*-2] [Z] ([C])', 'en', 'AD', 'IST') "/>

将使用公历 (AD) 将给定的 GMT 日期事件计算为印度标准时间 (IST),但它只是打印:

would calculate the given GMT date event into Indian Standard Time (IST) with Gregorian Calendar (AD) but it just prints:

7 July 2013 11:08PM +00:00 (Gregorian)

所以它不会改变时区.要移动时区,我们必须使用:

So it does not shift the time zone. To shift the time zone we must use:

adjust-dateTime-to-timezone

但是这个函数只接受以小时/分钟为单位的持续时间,而不是时区,以便处理器确定是否有夏令时.

But this function accepts only a duration in number of hours/minutes, not a TimeZone so that the processor determines if there is DST or not.

任何建议,请

推荐答案

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

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>

这篇关于将纪元转换为日期 &amp;xslt 2.0 中的时区时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆