【问题标题】:xslt time date conversionxslt时间日期转换
【发布时间】:2012-02-28 05:00:13
【问题描述】:

我有两个带有 putdate 和 puttime 的变量(格式为 HHMMSSTH)。这两个变量取自 mqmd 头文件。

<xsl:variable name="putdate">
        <xsl:value-of select="'20051114'"/>
      </xsl:variable>
      <xsl:variable name="puttime">
        <xsl:value-of select="'10594016'"/>
      </xsl:variable>

puttime的格式是HHMMSSTH

HH
Hours (00 to 23)
MM
Minutes (00 to 59)
SS
Seconds (00 to 59)
T
Tenths of a second (0 to 9)
H
Hundredths of a second (0 to 9).

我有第三个变量,增量时间,以毫秒为单位,在本例中为 1990 毫秒。我需要 xslt 做的是将值 1990 毫秒添加到 puttime,我想下面是步骤

1) Take the 10th value, which is 9(from 1990), then add to puttime's H, which makes it 10594025(9+6=15)
2)Take the 100th value, which is 9(from 1990), then add to puttimes's T, which makes it 10594115(9+2=11)
3)Take the 1000th value, which is 1(from 1990), then add to puttime's SS, which makes it 10594215

结果时间是 10594315。xslt 的输出应该是“2005-11-14 10:59:42:15”(实际上是格林威治标准时间),转换为山区时间。

【问题讨论】:

    标签: xml xslt date xslt-1.0


    【解决方案1】:

    XSLT 1.0 没有对时间值的任何内置支持。为了能够添加到时间值,您必须自己实现所有溢出逻辑。

    • 分数 ≥ 100 ⇒ 增量秒
    • 秒 ≥ 60 ⇒ 增量分钟
    • 分钟 ≥ 60 ⇒ 增加小时数
    • 小时 ≥ 24 ⇒ 递增天数
    • 天数 ≥ 28、29、30 或 31 ⇒ 递增月数
    • 月 ≥ 12 ⇒ 增量年

    然后你还必须处理 DST 规则,否则当切换日期过去时,值会被弄乱。如果你确实设法实现它,它最终将成为一大块无法维护的代码。

    在 XSLT 2.0 中,您拥有可以为您进行计算的 xs:dateTime 类型(和类似类型)。在 XSLT 2.0 甚至命令式编程语言(Java、C#、Python 等)中执行此操作会简单得多。

    【讨论】:

    猜你喜欢
    • 2022-01-11
    • 2017-10-01
    • 2017-06-23
    • 2020-10-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多