Getting Notification of System Time Change
Article Metadata
Code Example
Article
For getting the Notification of System Time Change, we can use RTimers.
The At timers terminates with KErrAbort when the system time changes, the timer can be used to monitor changes in system time.
Implement a simple Active Object and Use RTimer to get notification of System Change.
To get complete idea about Active Object with example refer Active Objects section on wiki.
TTime CurrentTime;
CurrentTime.HomeTime();
// Issue an Asynchronous Request //
iTimeWaster.At(iStatus, CurrentTime + TTimeIntervalYears(2));
// set it to active once request is issued //
SetActive();
Now in the RunL() of your Active Object, you can catch KErrAbort when the System Time is changed, as timer will terminate with KErrAbort when the system time is changed.
void CSomeActiveObject::RunL()
{
// This is the case when system time is changed and
// hence will cause the timer to abort with KErrAbort.
if(iStatus.Int() == KErrAbort)
{
// Do Something ...
}
}
For testing the System Time Change Notification, you can run your program in the background and change the system time from Tools >> Clock >> Settings >>Time, your RunL() method will be called with iStatus = KErrAbort.
See the ready to run example.
"HelloWorldBasic(TimeChanged).zip" File:Helloworldbasic(TimeChanged).zip


There is another better way for this with the use of CEnvironmentChangeNotifier. Check this link: Environment Change Notifier.