Determine if the system clock has changed?

I am considering the idea of ​​a Java project that detects when a computer clock has been changed. The idea is to write the date and time on a computer clock and save it in a file. Then I want to be able to run rules on it that show a message if the clock has been changed. I also consider rules such as "Allowing no more than 5 minute changes." This allows the convenience of changing the time for an odd minute.

I also need to include the changes that the watch makes. For example, at an hour or an hour at an hour at a certain time of the year (British time).

I'm not sure there is already a Java system that does this, which I could look at, but I literally don't know where to start.

+5
source share
7 answers

Java still gets all the time / date information from the system clock, so there is no way to find out if the base system clock has been changed. If you take the date and time and save it in a file - this will determine whether the time was set (i.e., the time in the file after the current time and there was no DST) - but it cannot determine the time when the time was set (t .e. time in the file 2 hours before the current time) 2 hours have passed, or did the user set the clock ahead to 2 hours until the program was launched?). The only way to do something like this is to use the famous Time Server , and instead of saving time in a file, save the offset between the time server and the local system clock.

+1
source

, - (CBATG).

. diff 5 , , .

+1

-: veeeery. java.util.Timer . Calender .

http://java.sun.com/javase/6/docs/api/ .

, . .

0

Joda time. , DST DST, .

0

, , , , . . , , .

0

, , , , . ( , , ) , 60 , .

: 0 12:00:00 1 12:01:00 ( ) 12:00:00 ( ), , . ... n xx: yy: zz, 60 , . ...

, , , , . , , .

0

, :

. -, , . UTC, DST /sysadmin.

java.time. , java.time, , .

Instant now1 = Instant.now(); // Record, run again, compare.
String now1AsString = now1.toString();  // Ex: 2011-12-03T10:15:30.724Z
Instant now2 = Instant.now();  
Boolean timeWentBackwards = now2.isBefore( now1 );

, , . .

- . () , , , . , , . , " ".

DST roll-overs

. ​​ - UTC. -, .

: DST - , , .

0

All Articles