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
Luc The Perverse - 16 Nov 2006 05:18 GMT
> Hi all ,
> I'd really appreciate an insight on this ..
[quoted text clipped - 14 lines]
>
> 06:03:00 - 06:00:00 = 12:03:00 WHY ? I want my answer to be 00:03:00
Maybe you need to learn to differentiate a Date/Time from a time span
When you subtract one date from another you get a time span - not a new
date - if that helps ;)
Think about what you are really seeing
If you take 6:03:00 (in seconds) and subtract 6:00:00 (in seconds) you will
get 3 minutes. And what time is three minutes into the day? I'll give
you a hint - there is no zeroth hour
--
LTP
:)
Mark Space - 16 Nov 2006 17:24 GMT
> you a hint - there is no zeroth hour
Well, in military time there is. Maybe he can get the result he wants
by changing the formatting of the output. Left as an exercise for the
reader, I'm too lazy to look it up.
Luc The Perverse - 17 Nov 2006 00:26 GMT
>> you a hint - there is no zeroth hour
>
> Well, in military time there is. Maybe he can get the result he wants by
> changing the formatting of the output. Left as an exercise for the
> reader, I'm too lazy to look it up.
He needs to use the classes in the way they were indended, not find
workarounds.
What is wrong with something like this?
String fTime(int numSecs){
int se = numSecs%60;
numSecs/=60;
int mi = numSecs%60
int hr = numSecs/60;
String[] va = {"0" + Integer.toString(hr), "0" + Integer.toString(mi),
"0" + Integer.toString(se)};
String ret = "";
for(String c : va){
if(!ret.equals(""))
ret+=":";
ret+=c.substring(c.length() - 2);
}
return ret;
}
(Note I have not compiled this - so it may have errors)
--
LTP
:)
Danno - 16 Nov 2006 05:21 GMT
> Hi all ,
> I'd really appreciate an insight on this ..
[quoted text clipped - 16 lines]
>
> Thanks alot
06:03:00 - 6:00:00 = 180000ms
if you make a date out of 180000ms you get 12:03:00 AM. Because all
dates start on January 1, 1970 12:00:00 AM GMT.
Danno - 16 Nov 2006 05:30 GMT
> Hi all ,
> I'd really appreciate an insight on this ..
[quoted text clipped - 16 lines]
>
> Thanks alot
BTW, change your simpleDateFormat construct to this:
SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm:ss");
see if that works for ya. My previous post applies, BTW
alomrani@gmail.com - 16 Nov 2006 05:45 GMT
SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm:ss");
> Hi all ,
> I'd really appreciate an insight on this ..
[quoted text clipped - 16 lines]
>
> Thanks alot