• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Convert 5.5 to 5:30 format

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My program gets an time input in foll format :-"5.5" hours.
It implies 5hours 30 minutes.
I need a function to format this data in "5:30" format(for using it for timezone) .
Is there any available java classes to do the same or i have to use string manipulation functions ?
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have a look at the API documentation of class java.text.SimpleDateFormat.
 
Ranch Hand
Posts: 781
Netbeans IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Jesper Young:
Have a look at the API documentation of class java.text.SimpleDateFormat.



I don't think (but could be wrong) that there is a anything in SimpleDateFormat to deal with decimal hours and I supect you are going to have to deal with this yourself.

P.S. It is normally wrong to use Date and SimpleDateFormat to process 'elapsed time' since SimpleDateFormat handles TimeZones, LeapYears, Leap seconds and daylight saving which do not figure in 'elapsed time'. You can get away with it for small 'elapsed time' but ...
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try to solve problems as simplistically as possible. This is a simple mathematical problem, just multiply the decimal (.5) with the maximum amount (60) and you get 30 (as in minutes).

It might be a nifty component to have something automatically get the actual time from a decimal format, but most of the time it is best to find the simplest solution.

Plus overcomplicating problems is my M.O.

--Six
 
reply
    Bookmark Topic Watch Topic
  • New Topic