将十进制小时转换为小时、分钟和秒

2024-01-19

xslt 1.0 中是否有更优雅的解决方案?我知道 xslt 2.0 有内置函数。

我正在获取一个以十进制小时表示的数字,需要将其表示为 HH:MM:SS。目前我有以下功能正常的。

<xsl:variable name="decimal_hours" select="pre_lab_cost div pre_labour_rate"/>
<xsl:variable name="decimal_minutes" select="number(concat('0.',substring-after($decimal_hours, '.')))*60"/>
<xsl:variable name="decimal_seconds" select="number(concat('0.',substring-after($decimal_minutes, '.')))*60"/>
<xsl:value-of select="concat(format-number(floor($decimal_hours), '00'),
                                           ':',
                                           format-number(floor($decimal_minutes), '00'),
                                           ':',
                                           format-number(floor($decimal_seconds), '00')
                                           )"/>

这个怎么样 ...

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>

<xsl:variable name="decimal_hours" select="3.14"/>

<xsl:template match="/">
<xsl:value-of select="concat(
  format-number(floor($decimal_hours              ), '00:'),
  format-number(floor($decimal_hours *  60 mod  60), '00:'),
  format-number(floor($decimal_hours * 360 mod 360), '00'))"/>
</xsl:template>

</xsl:stylesheet>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

将十进制小时转换为小时、分钟和秒 的相关文章

随机推荐