![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Nov 2004
Posts: 21
Rep Power: 0
![]() |
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); 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> |
|
|
|
|
|
#2 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
Can we see the rest of the code?
|
|
|
|
|
|
#3 |
|
Hobbyist Programmer
Join Date: Apr 2004
Location: Texas
Posts: 106
Rep Power: 5
![]() |
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! */ |
|
|
|
|
|
#4 |
|
Newbie
Join Date: Nov 2004
Posts: 16
Rep Power: 0
![]() |
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 ![]() |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|