Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

milliseconds to hh:mm:ss format  RSS feed

 
Brian Percival
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

<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: 65824
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Investigate the actions of the JSTL fmt tags.
 
Brian Percival
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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..
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!