i,ve got a problem which i cant solve at the moment. I already googled for it and found some solutions, but all of them not rly match my problem.
So i get 2 Strings from SQL Database in the format hh:mm:ss.
The first String is a time, for example "14:30:00" and the second String is a value of minutes for example "00:15:00"
Now i wanna add the second Time to the first time. After that i'll try to substract the actual time from this time to get the difference.
All of this should work without a Date, just the time.
Would be nice if someone could help me
Best How To :
First, a 'time' without a date is not valid. Think about daylight saving time etc.
One solution is maybe to create two date objects (with a fixed date) and use them for your calculation. Or parse the string and use TimeUnit to work with the values.
Keep in mind that you can't just sum the parts of your timestring one by one (e.g. 20:45:58 + 00:20:10 = 20:05:08 ) !
So if you decide to parse, make your life easier and use http://developer.android.com/reference/java/util/concurrent/TimeUnit.html to bring your values to a base (seconds) do your calculations and bring the result to the format you wish.
The Calendar class can also be a solution (but keep daylight saving in mind!):
Date date = new Date();
Calendar cal = Calendar.getInstance();
cal.setTime( date );
cal.set( Calendar.HOUR_OF_DAY, 20 );
cal.set( Calendar.MINUTE, 15 );
cal.set( Calendar.SECOND, 0 );
cal.set( Calendar.MILLISECOND, 0 );
cal.add( Calendar.MINUTE, 22 );
date = cal.getTime();