Jump to content

Milliseconds to hh:mm:ss with 60seconds


Loriot

Recommended Posts

Hi all,I got a very nice little extra template that transforms a millisecond value to hh:mm:ss. But now I found out that it failes in one special case: If I have something that is 1min 59sec and 990 msec, than I get 1:60 instead of 2 min. Somebody out there that knows how to transform that correctly?My calltemplate:

	<xsl:decimal-format name="european" decimal-separator=","/><xsl:template name="processLength">	<xsl:param name="milliseconds"/>	<xsl:variable name="hours" select="floor($milliseconds div (1000*3600))"/>	<xsl:variable name="minutes" select="floor(($milliseconds mod (1000*3600)) div (1000*60))"/>	<xsl:variable name="seconds" select="($milliseconds mod (1000*60)) div 1000"/><xsl:value-of select="concat(format-number($hours, '#00'), ':',format-number($minutes, '00'), ':', format-number($seconds, '00', 'european'))"/></xsl:template>

Help would be thankfully taken!:)

Link to comment
Share on other sites

From my calculations, it appears the result of the monites of 119990ms is 1,9998333333333333333333333333333min.Scince you're using floor(), you're getting the least integer value, which in this case is rightfully 1. Use round() instead.As for the seconds, they appear like that simply because there's nothing to "reset" them when they reach exactly 60. Here's something I think should work:

<xsl:decimal-format name="european" decimal-separator=","/><xsl:template name="processLength">	<xsl:param name="milliseconds"/>	<xsl:variable name="hours" select="floor($milliseconds div (1000*3600))"/>	<xsl:variable name="minutes" select="round(($milliseconds mod (1000*3600)) div (1000*60))"/>	<xsl:variable name="seconds" select="(($milliseconds mod (1000*60)) div 1000)"/>	<xsl:value-of select="concat(format-number($hours, '#00'), ':',format-number($minutes, '00'), ':')"/>	<xsl:choose>		<xsl:when test="$seconds >= 60">			<xsl:value-of select="format-number($seconds, '00', 'european')"/>		</xsl:when>		<xsl:otherwise>00</xsl:otherwise>	</xsl:choose></xsl:template>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...