Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Java in General
Search Coderanch
Advance search
Google search
Register / Login
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
Ron McLeod
Tim Cooke
Liutauras Vilda
Jeanne Boyarsky
Sheriffs:
Paul Clapham
Rob Spoor
Junilu Lacar
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Piet Souris
Carey Brown
Bartenders:
Forum:
Java in General
Calculate a Time Based on Known Date Plus Decimal Hours
Steve Dyke
Ranch Hand
Posts: 2156
2
posted 7 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I need to generate a calculated finish time based on a known start date and the hours spent to complete it.
My code works good unless the hours spent are less than 1 or the hours have a fraction.
public HoursCalculator(String seedDate, float hours){ Calendar cal = Calendar.getInstance(); try{ cal.setTime(new SimpleDateFormat("MM/dd/yyyy HH:mm").parse(seedDate)); } catch(ParseException pe){ System.out.println("HoursCalculator2: "+pe); } cal.add(Calendar.HOUR, (int)hours); SimpleDateFormat formatter = new SimpleDateFormat("HH:mm"); ehours = formatter.format(cal.getTime()); }
Norm Radder
Rancher
Posts: 4904
38
posted 7 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
unless the hours spent are less than 1 or the hours have a fraction.
How would you calculate the end date if you did it by hand? The Calendar class can add units of time besides hours. Can you convert the non-integer hours to some other time units?
Tony Docherty
Bartender
Posts: 3323
86
posted 7 years ago
2
Number of slices to send:
Optional 'thank-you' note:
Send
If you are using
Java
8 you may want to look at the new java.time API which makes it so much easier to handle times.
Don't get me started about those stupid
light bulbs
.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Calendar shows incorrect date
How to subtract the date value
Strange problem in date calculation (IS IT BUG!!!)
Time Zone problem
Adding days to January 1, 1900
More...