Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Nov 19th, 2004, 3:20 PM   #1
T3FLoN
Newbie
 
Join Date: Nov 2004
Posts: 21
Rep Power: 0 T3FLoN is on a distinguished road
for skool they got me making a telephone witch is done and now my teacher added a phone bill to it...hes having us save the info of the number dialed time/date and duration of the call.

now im using the getTime() method witch returns the time in milliseconds since 1970 to now.
well i get both my longs witch are timeStart and timeEnd both get assigned a value as calls are made.
now i need to find the diferende of the 2 and store it in timeDuration witch is also a long.

my problem is that when i do this line.
durationTime = (timeEnd - timeStart);
its not giving me a correct answer just gives me timeEnd.
thats all the code ull need to give me a hand cause all else works as it should just not that equation.
BTW im Sys.out.printing them to see the values thats how i kno they are incorrect.
any insite would be appreciated.TX
__________________
<span style='font-family:Courier'><span style='font-size:12pt;line-height:100%'><span style='color:orange'>☼☼☼ Just kill em all, and let God sort em out. ☼☼☼</span></span></span>
T3FLoN is offline   Reply With Quote
Old Nov 19th, 2004, 3:27 PM   #2
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Can we see the rest of the code?
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Nov 19th, 2004, 4:00 PM   #3
sykkn
Hobbyist Programmer
 
Join Date: Apr 2004
Location: Texas
Posts: 106
Rep Power: 5 sykkn is on a distinguished road
If all of your values are indeed longs, then you should not be having a problem subtracting the two values.

import java.util.*;

class timetest {
    public static void main(String args[]) {
        long startStamp = new Date().getTime();

        try {
            Thread.sleep(500);
        } catch(Exception e) { }

        long endStamp = new Date().getTime();

        long diffStamp = (endStamp - startStamp);

        System.out.println("Start Stamp: " + startStamp);
        System.out.println("End Stamp: " + endStamp);
        System.out.println("Diff Stamp: " + diffStamp);
    }
}

jowings-pb:~/devel/java jowings$ java timetest
Start Stamp: 1100901620140
End Stamp: 1100901620640
Diff Stamp: 500
__________________
[ [ SykkN alloc ] initWithThePowerTo: destroyYouAll ];
/* Don't make me use it! */
sykkn is offline   Reply With Quote
Old Nov 21st, 2004, 6:51 PM   #4
eccles
Newbie
 
Join Date: Nov 2004
Posts: 16
Rep Power: 0 eccles is on a distinguished road
pay careful attention to Sykkn's example.

note that he is creating a new Date instance each time he wants to get the curent time...

ie he is NOT doing:
Date date = new Date();
long timeStart = date.getTime();
... 
long timeEnd = date.getTime();
long duration = timeEnd - timeStart;

which was my initial thought about what you might be doing, but if you are getting the end time instead of zero then perhaps you aren't.

but yeah - just look at that correct example and you might see where you went wrong.

oh - and if you don't know where you are going wrong with something - don't assume that all people with need to see is a single line of your code - one which clearly has nothing wrong with it
eccles is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 4:48 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC