需要 XSLT 中的时区转换帮助 [英] Need help in XSLT for timezone conversion

查看:37
本文介绍了需要 XSLT 中的时区转换帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的 XML 数据,我需要通过 XSLT 将时区更改为印度时间

This is my XML data i need to change the time zone into indian time through XSLT

2016-05-31T16:45:37.556Z

2016-05-31T16:45:37.556Z

请帮忙解决这个问题

问候,湿婆

推荐答案

尝试:

<xsl:template name="UTC-to-Indian">
    <xsl:param name="dateTime"/>

    <xsl:variable name="date" select="substring-before($dateTime, 'T')" />
    <xsl:variable name="time" select="substring-before(substring-after($dateTime, 'T'), 'Z')" />

    <xsl:variable name="year" select="substring($date, 1, 4)" />
    <xsl:variable name="month" select="substring($date, 6, 2)" />
    <xsl:variable name="day" select="substring($date, 9, 2)" />

    <xsl:variable name="hour" select="substring($time, 1, 2)" />
    <xsl:variable name="minute" select="substring($time, 4, 2)" />
    <xsl:variable name="second" select="substring($time, 7)" />

    <xsl:variable name="a" select="floor((14 - $month) div 12)"/>
    <xsl:variable name="y" select="$year + 4800 - $a"/>
    <xsl:variable name="m" select="$month + 12*$a - 3"/>    
    <xsl:variable name="jd" select="$day + floor((153*$m + 2) div 5) + 365*$y + floor($y div 4) - floor($y div 100) + floor($y div 400) - 32045" />

    <xsl:variable name="total-seconds" select="86400*$jd + 3600*$hour + 60*$minute + $second + 19800" />

    <xsl:variable name="new-jd" select="floor($total-seconds div 86400)"/>  
    <xsl:variable name="new-hour" select="floor($total-seconds mod 86400 div 3600)"/>
    <xsl:variable name="new-minute" select="floor($total-seconds mod 3600 div 60)"/>
    <xsl:variable name="new-second" select="$total-seconds mod 60"/>

    <xsl:variable name="f" select="$new-jd + 1401 + floor((floor((4 * $new-jd + 274277) div 146097) * 3) div 4) - 38"/>
    <xsl:variable name="e" select="4*$f + 3"/>
    <xsl:variable name="g" select="floor(($e mod 1461) div 4)"/>
    <xsl:variable name="h" select="5*$g + 2"/>
    <xsl:variable name="D" select="floor(($h mod 153) div 5 ) + 1"/>
    <xsl:variable name="M" select="(floor($h div 153) + 2) mod 12 + 1"/>
    <xsl:variable name="Y" select="floor($e div 1461) - 4716 + floor((14 - $M) div 12)"/>

    <xsl:value-of select="concat($Y, format-number($M, '-00'), format-number($D, '-00'))"/>
    <xsl:text>T</xsl:text>
    <xsl:value-of select="concat(format-number($new-hour, '00'), format-number($new-minute, ':00'), format-number($new-second, ':00.###'))"/>
    <xsl:text>+05:30</xsl:text>
</xsl:template>

调用示例:

XML

<datetime>2016-05-31T19:45:15.123Z</datetime>

XSLT

<xsl:template match="datetime">
    <xsl:copy>
        <xsl:call-template name="UTC-to-Indian">
            <xsl:with-param name="dateTime" select="."/>
        </xsl:call-template>
    </xsl:copy>
</xsl:template>  

结果

<?xml version="1.0" encoding="UTF-8"?>
<datetime>2016-06-01T01:15:15.123+05:30</datetime>

这篇关于需要 XSLT 中的时区转换帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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