How to measure time when being logged in
I want to implement a project where I check system timings whenever I am logged in. If I enter the office and log in my system the I should get the time and also when I go for a br开发者_运维百科eak I just lock my PC and go so at that time time should stop and again when I login it should start.
Basically it should show me the total time I was logged in my computer/PC.
In java you can obtain the time by several ways. Two of them are :
instanciate a new Date object : Date myDate = new Date() ;
using : System.currentTimeMillis()
I think you should think of using a software dedicated to that instead of implementing this in Java.
What you could do is this:
Create a Java application that can log the time somewhere, using the
System.currentTimeMillis()
ornew Date()
approach.Create a scheduled task in windows that runs each time the user locks, unlocks, logs on and logs off the system. This scheduled task should run your application. It should be as simple as calling a batch file which in turn invokes your Java application.
The application should use all the times captured to calculate the effective time.
You can use System.currentTimeMillis()
(or System.nanoTime()
) for the start and the end, and then calculate the difference.
This will give you the time when you start / close Java. Linking this to system startup / system shutdown can be done by launching the application on startup. But that depends on the OS.
精彩评论