A cross platform NTP client library for .Net platforms. Allows you to easily retrieve an accurate, current date & time from internet NTP servers.
A cross platform NTP client library for .Net platforms. Allows you to easily retrieve an accurate, current date & time from internet NTP servers.
Currently;
** Supports async/await
PM> Install-Package Yort.Ntp.Portable
For platforms that support task based async;
var client = new Yort.Ntp.NtpClient();
var currentTime = await client.RequestTimeAsync();
For platforms that do not support async/await or tasks (or if you don't want to use async/await);
var client = new Yort.Ntp.NtpClient();
client.TimeReceived += Client_TimeReceived;
client.ErrorOccurred += Client_ErrorOccurred;
client.BeginRequestTime();
private void Client_ErrorOccurred(object sender, NtpNetworkErrorEventArgs e)
{
//TODO: Handle errors here.
}
private void Client_TimeReceived(object sender, NtpTimeReceivedEventArgs e)
{
//TODO: Use retrieved time here. Time is provided by e.CurrentTime.
System.Diagnostics.Debug.WriteLine(e.CurrentTime);
}
The icon for this project is Computer Time by Arthur Shlain from the Noun Project and is used under the Creative Commons License.