Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > 06:03:00 - 06:00:00 = 12:03:00 WHY ?

Reply
Thread Tools

06:03:00 - 06:00:00 = 12:03:00 WHY ?

 
 
alomrani@gmail.com
Guest
Posts: n/a
 
      11-16-2006
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

 
Reply With Quote
 
 
 
 
Luc The Perverse
Guest
Posts: n/a
 
      11-16-2006
<> wrote in message
news: ups.com...
> 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


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




 
Reply With Quote
 
 
 
 
Danno
Guest
Posts: n/a
 
      11-16-2006

wrote:
> 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


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.

 
Reply With Quote
 
Danno
Guest
Posts: n/a
 
      11-16-2006

wrote:
> 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



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

 
Reply With Quote
 
alomrani@gmail.com
Guest
Posts: n/a
 
      11-16-2006
SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm:ss");
wrote:
> 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


 
Reply With Quote
 
Mark Space
Guest
Posts: n/a
 
      11-16-2006
Luc The Perverse wrote:
> 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.
 
Reply With Quote
 
Luc The Perverse
Guest
Posts: n/a
 
      11-17-2006
"Mark Space" <> wrote in message
news:s917h.11134$ et...
> Luc The Perverse wrote:
>> 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




 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
why why why why why Mr. SweatyFinger ASP .Net 4 12-21-2006 01:15 PM
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
Cisco 2611 and Cisco 1721 : Why , why , why ????? sam@nospam.org Cisco 10 05-01-2005 08:49 AM
Why, why, why??? =?Utf-8?B?VGltOjouLg==?= ASP .Net 6 01-27-2005 03:35 PM
Why Why Why You HAVE NO IDEA MCSE 31 04-24-2004 06:40 PM



Advertisments