将十进制小时转换为小时、分钟和秒 [英] Converting decimal hours to hours minutes and seconds
本文介绍了将十进制小时转换为小时、分钟和秒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 xslt 1.0 中是否有更优雅的解决方案?我知道 xslt 2.0 有内置函数.
Is there a more elegant solution to the following in xslt 1.0? I understand there are built in functions to xslt 2.0.
我采用十进制小时数,需要将其表示为 HH:MM:SS.目前我有以下功能很好.
I'm taking a number in decimal hours and need to represent it as HH:MM:SS. At the moment I have the following which functions well.
<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>
这篇关于将十进制小时转换为小时、分钟和秒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文