Question:
06:03:00 - 06:00:00 = 12:03:00 Why ?
Amber G
2006-11-15 20:43:40 UTC
Hi all ,
I'd really appreciate an insight on this ..

i am trying to subtract two date values

dateS = "06:03:00"
dateE = "06:00:00"

SimpleDateFormat timeFormat = new SimpleDateFormat("hh:mm:ss");
timeFormat.setTimeZone(TimeZone.getTimeZone("GMT"));

java.util.Date dateStart = timeFormat.parse(dateS);
java.util.Date dateEnd = timeFormat.parse(dateE);

long diff = dateStart.getTime() - dateEnd.getTime();
return timeFormat.format(new Date(diff));


06:03:00 - 06:00:00 = 12:03:00 WHY ? I want my answer to be 00:03:00

Thanks alot
Five answers:
shadowkat
2006-11-15 20:46:27 UTC
Java may be returning the 12-hr format of the time. That would be 12:03:00 AM. You would need to format it for 24-hr, that would return 00:03:00
Rollercoaster
2006-11-15 20:51:03 UTC
I dun even know programming, but it's kinda like common sense to me. if you take 06:00:00 hours (6 hours) away from 06:03:00, that is go back 6 hours from the time 06:03:00(be it am or pm)the time value will be 12:03:00. If you want your answer to be 00:03:00, you can try adding 06:00:00 to 06:03:00 or take away 12:00:00 from 12:03:00. No gurantee thou.
D
2006-11-15 20:55:19 UTC
Honestly the logic of this is beyond me (being as how you have 6:00 - 6:03 and you expect to get 3:00 out of it) but I do have an answer to your question, it may be Java is converting it to a different time setting than you want 24 h. Therefore use an If, else if, else statment to convert the time between the two.



for example



if ((time =>13:xx:xx) && (time <= 13:xx:xx))

time == 01:xx:xx



Please note this was just an example of what I was tring to imply.
Cynthia B
2006-11-15 20:47:02 UTC
sounds, looks like military time instead of 12to 12 it is done in 24 hr. increments
ChantiĀ®
2006-11-15 20:48:33 UTC
Because its arule..Rule is rule, Rule for all


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...