Formatting a period of time

Tags: , , , , ,
Posted in dotnet, vb, vb.net | No Comments »

In Java I have a long integer representing a period of time in milliseconds. The time period could be anything from a couple of seconds to a number of weeks. I would like to output this time period as a String with the appropriate unit.

For example 3,000 should be output as “3 seconds”, 61,200,000 should be output as “17 hours” and 1,814,400,000 should be output as “3 weeks”.

Ideally I would also be able to fine-tune the formatting of sub-units, e.g. 62,580,000 might be output as “17 hours, 23 minutes”.

Are there any existing Java classes that handle this?

Similar:

  1. Formatting time between Rails and Javascript — avoiding duplicating code across languages I have a view that takes a Ruby Date, performs some formatting on it to output just the time in the format [5:30 PM]. Then...
  2. string.Format of a timer? I’ve a time ticker event, I want to write it to a label in format ( hours:minutes:seconds 00:00:00 ) it does not print the 0...
  3. How can a Timespan-Day last only for 8 Hours? I have saved a duration in minutes and want to have an output “1 day 5 hours 30 minutes”. Currently i add the minutes to...
  4. Create event handlers with using methods and parameters A Convert button with a Click event handler that accepts an integer from the user (use a textbox for the input), stores the value in...
  5. Time code IS the following code correct? mscount++; /* Generate 1ms Delay*/ if(mscount>=1000) { mscount=0; Seconds++; if(Seconds>=60) { Seconds=0; Minutes++; if(Minutes>=60) { Minutes=0; Hours++; if(Hours>=13) { Hours=1;...

Tags: , , , , ,

Leave a Reply