aspose file tools*
The moose likes Java in General and the fly likes Adding value to A Time Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Adding value to A Time" Watch "Adding value to A Time" New topic
Author

Adding value to A Time

Alec Lee
Ranch Hand

Joined: Jan 28, 2004
Posts: 569
I have a String of the form "03:20:10,132" representing a time value. What is the simpliest way to add an arbitrary time value to it? I think it isn't a good choice to manually parse the string to identify which is hour, minute and second. Is there a faster method?
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

Try to play with the Calendar class.


[My Blog]
All roads lead to JavaRanch
mohit bahl
Ranch Hand

Joined: Mar 22, 2006
Posts: 48
Hi,
One way of solving your problem is that you can use the SimpleDateFormat calss to convert this String to a Date object. Then using this date object you can build/set a GregorianCalendar Object. And using the add function of this GregorianCalendar class you can add any number to any field, like hour minute or seconds.
Just remember one thing, when you create date object by providing only the time details, date is defaulted to Jan 01 1970.

Hope this gives you some direction to work on.

cheers!


to err is human, but the company policy doesn't allow it!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Adding value to A Time