首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >xslt时间日期转换

xslt时间日期转换
EN

Stack Overflow用户
提问于 2012-02-28 13:00:14
回答 1查看 874关注 0票数 0

我有两个变量,分别是putdate和puttime(格式为HHMMSSTH)。这两个变量取自mqmd报头。

代码语言:javascript
复制
<xsl:variable name="putdate">
        <xsl:value-of select="'20051114'"/>
      </xsl:variable>
      <xsl:variable name="puttime">
        <xsl:value-of select="'10594016'"/>
      </xsl:variable>

puttime的格式为HHMMSSTH

代码语言:javascript
复制
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).

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

代码语言:javascript
复制
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“(实际上是在GMT中),并转换为Mountain Time。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-02-28 15:41:43

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

seconds

  • Seconds minutes

  • Minutes months

  • Months

≥28,29,30⇒≥31⇒Increment minutes

  • Minutes

≥28,29,30 or 31⇒Increment months

  • Months≥28,29,30 or 31⇒Increment months

  • Months≥28,29,30 or 31⇒Increment

⇒≥12⇒Increment months

  • Months≥12⇒Increment⇒≥≥28,29,30 or 31⇒Increment minutes

  • Minutes≥12⇒Increment≥12⇒Increment

≥≥28,29,30 or 31⇒Increment

  • ≥12⇒Increment≥12⇒Increment

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

在XSLT2.0中,xs:dateTime类型(和类似类型)可以为您完成计算。使用XSLT2.0甚至是命令式编程语言(Java、C#、Python等)会简单得多。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9476646

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档