Provides a set of methods that help developers to manage the SNTP (Simple Network Time Protocol) client on the target device.
For a list of some public NTP servers, see this link : http://support.ntp.org/bin/view/Servers/NTPPoolServers
예제 #1
0
        private static void SetDateTime()
        {
            int retryCount = 30;

            Console.WriteLine("Waiting for a valid date & time...");

            // if SNTP is available and enabled on target device this can be skipped because we should have a valid date & time
            while (DateTime.UtcNow.Year < 2018)
            {
                // force update if we haven't a valid time after 30 seconds
                if (retryCount-- == 0)
                {
                    Console.WriteLine("Forcing SNTP update...");

                    Sntp.UpdateNow();

                    // reset counter
                    retryCount = 30;
                }

                // wait for valid date & time
                Thread.Sleep(1000);
            }

            Console.WriteLine($"We have valid date & time: {DateTime.UtcNow.ToString()}");

            DateTimeAvailable.Set();
        }
예제 #2
0
        private static void SetDateTime()
        {
            Console.WriteLine("Setting up system clock...");

            // if SNTP is available and enabled on target device this can be skipped because we should have a valid date & time
            while (DateTime.UtcNow.Year < 2018)
            {
                Sntp.UpdateNow();

                Console.WriteLine("Waiting for valid date time...");
                // wait for valid date & time
                Thread.Sleep(1000);
            }

            DateTimeAvailable.Set();
        }