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..

Edited 5 Years Ago by Krokcy: n/a

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.

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!! :)

This question has already been answered. Start a new discussion instead.