A cross platform NTP client library for .Net platforms. Allows you to easily retrieve an accurate, current date & time from internet NTP servers.
Currently;
- .Net Framework 4.0+
- .Net Framework 4.5+ **
- Windows Phone Silverlight (8.1+)
- Xamarin.iOS **
- Xamarin.Android **
- WinRT (Windows Store Apps 8.1) **
- UWP 10+ (Windows 10 Universal Programs) **
- .Net Standard 1.3
** 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.