English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

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

2006-11-15 15:43:40 · 5 answers · asked by Amber G 1 in Computers & Internet Programming & Design

5 answers

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

2006-11-15 15:46:27 · answer #1 · answered by shadowkat 5 · 0 0

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.

2006-11-15 15:51:03 · answer #2 · answered by Rollercoaster 4 · 0 0

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.

2006-11-15 15:55:19 · answer #3 · answered by D 4 · 0 0

sounds, looks like military time instead of 12to 12 it is done in 24 hr. increments

2006-11-15 15:47:02 · answer #4 · answered by Cynthia B 3 · 0 0

Because its arule..Rule is rule, Rule for all

2006-11-15 15:48:33 · answer #5 · answered by Chanti® 3 · 0 0

fedest.com, questions and answers