Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2006

Tip: Looking for answers? Try searching our database.

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

Thread view: 
alomrani@gmail.com - 16 Nov 2006 04:40 GMT
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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.