954,549 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

java.util.date

Oka. So i have this rather simple program, basically i want it to be able to count the number of hours it has been open.
My problem is that i am trying to use

import java.util.date;

Calendar calendar = Calendar.getInstance();


And apperently this does not update after the program has been launched. is there a work around? or am i just using it wrong?
Basically what im trying to do (for the lack of knowlagde on how to do it better =) ):

int time;
                    int time2;

                    
                    time = calendar.get(Calendar.SECOND);

                    String containerInput;
                    containerInput = reader.readLine(); /*input to keep the program running*/

                    System.out.println(containerInput); //because my compiler complains *when the string is unused*/
                    time2 = calendar.get(Calendar.SECOND);


I have tried to do longer dummy loops to keep the program active as i thought the input request might have stopped the call from updating, i was wrong ^^

EDIT: i know it at the moment only gets seconds, but i cant w8 for one hour everytime i need to try the program..

Krokcy
Newbie Poster
12 posts since Sep 2010
Reputation Points: 10
Solved Threads: 3
 
Calendar calendar = Calendar.getInstance();
this does not update after the program has been launched.


Its an assignment statement that puts the current value of something in a variable.
If you want a new/current value assign it again now. i want it to be able to count the number of hours it has been open
Save the time when it was open. Get the current time. Divide by the number of units of time in an hour.
You can use the System.currentTimeMillis() method to get the time.

NormR1
Posting Expert
Moderator
6,677 posts since Jun 2010
Reputation Points: 1,138
Solved Threads: 656
 
Its an assignment statement that puts the current value of something in a variable. If you want a new/current value assign it again now.

Duuu'h, of course. Still quite! new at java so yeah stupid quetions. Thanks for your help, most appreciated!! :)

Krokcy
Newbie Poster
12 posts since Sep 2010
Reputation Points: 10
Solved Threads: 3
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: