Win a copy of The Way of the Web Tester: A Beginner's Guide to Automating Tests this week in the Testing forum!

# milliseconds to hh:mm:ss format

Brian Percival
Ranch Hand
Posts: 163
How do I do the conversion above in EL ? milliseconds is not a date equivalent, but just a period of time.

Paul Clapham
Sheriff
Posts: 21443
33
You can do arithmetic operations in EL if I'm not mistaken. And ordinary arithmetic operations are what you need here. Milliseconds = number mod 1000, subtract milliseconds from number and divide it by 1000, seconds = number mod 60, subtract seconds from number and divide it by 60, and so on.

Brian Percival
Ranch Hand
Posts: 163

<c:set var="dursec" value="\${(ep.duration - (ep.duration mod 1000))/1000}" />
<c:set var="durhr" value="\${(dursec - (dursec mod 3600)) / 3600}" />
<c:set var="temp" value="\${(dursec - (durhr *3600))}" />
<c:set var="durmin" value="\${ (temp - (temp mod 60)) / 60 }" />
<c:set var="dursec" value="\${dursec-durmin*60-durhr*60}" />
\${durhr} \${durmin} \${dursec}

This is what I got. Hope someone can clarify this is true. However it displays decimals. How do I coerce the values as integers ?

Bear Bibeault
Author and ninkuma
Marshal
Posts: 65278
95
Investigate the actions of the JSTL fmt tags.

Brian Percival
Ranch Hand
Posts: 163
Paul and Bear, thanks for your responses.

I looked at the fmt, got the display fine, but I couldn't figure out how to convert a x.0 type number to just 0x.

Should I look at the pattern attribute more? I thought I looked..