I have wrote this simple console app to test when we change the timezone manually on windows 7 using set date time window whether timechange event is triggered or not? The answer is YES it triggered but i am printing current time which is not showing properly..
static void Main(string[] args)
{
SystemEvents.TimeChanged += new EventHandler(SystemEvents_TimeChanged);
Console.Read();
}
static void SystemEvents_TimeChanged(object sender, EventArgs e)
{
Console.WriteLine(DateTime.Now);
}
Once you run console app and then try to change the timezone it always reflects one time change but then it somehow stuck to that time even if you change the timezone to different timezone or same.
Am I missing something?
to verify whether system time has changed or not i have opened command prompt and use date and 'time' command to print the current time which shows perfect according to timezone.
In Windows, Network Time Protocol (NTP) is responsible for displaying accurate time. It synchronises your system clock's time with that of other computer servers by communicating on the internet. When this synchronisation setting is not properly configured, it can lead to inaccurate time. Check the Service status.
In Date & time, you can choose to let Windows 10 set your time and time zone automatically, or you can set them manually. To set your time and time zone in Windows 10, go to Start > Settings > Time & language > Date & time.
I believe the system time zone is being cached. You can clear this cache though:
TimeZoneInfo.ClearCachedData();
Put that just before your DateTime.Now
call, and it looks like it works fine. (Works on my machine, anyway :)
EDIT: As noted in comments, it appears that in some cases you also need to call CultureInfo.CurrentCulture.ClearCachedData()
. I didn't, but I dare say it doesn't hurt to do so :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With