开发者

How to measure time when being logged in

开发者 https://www.devze.com 2023-02-12 17:45 出处:网络
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

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:

  1. Create a Java application that can log the time somewhere, using the System.currentTimeMillis() or new Date() approach.

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

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号