ByronAP.Net.Ntp 0.4.2

dotnet add package ByronAP.Net.Ntp --version 0.4.2
NuGet\Install-Package ByronAP.Net.Ntp -Version 0.4.2
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ByronAP.Net.Ntp" Version="0.4.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ByronAP.Net.Ntp --version 0.4.2
#r "nuget: ByronAP.Net.Ntp, 0.4.2"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install ByronAP.Net.Ntp as a Cake Addin
#addin nuget:?package=ByronAP.Net.Ntp&version=0.4.2

// Install ByronAP.Net.Ntp as a Cake Tool
#tool nuget:?package=ByronAP.Net.Ntp&version=0.4.2

ByronAP.Net.Ntp

ByronAP.Net.NTP is a .NET library that simplifies the usage of NTP (network time) servers.

Usage

using ByronAP.Net.Ntp;
using System;
using System.Threading.Tasks;

namespace NtpDemo
{
    class Program
    {
        static async Task Main(string[] args)
        {
            Console.WriteLine($"Fetching current time from network time server.{Environment.NewLine}");
            try
            {
                // try and query the NTP server (supports IPV4 and V6)
                var ntpResult = await NtpClient.GetNetworkTimeAsync();

                if (ntpResult == null)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("FAILED to get NTP time.");
                    Console.ResetColor();

                    return;
                }

                Console.WriteLine($"Server: {ntpResult.ServerAddress}");
                Console.WriteLine($"Local: {ntpResult.QueryTime:MM/dd/yy H:mm:ss.FFFF zzz}");
                Console.WriteLine($"NTP:   {ntpResult.NtpTime:MM/dd/yy H:mm:ss.FFFF zzz}");

                Console.ForegroundColor = Math.Abs(ntpResult.TimeDifference.TotalMilliseconds) > 5000 ? ConsoleColor.Red : ConsoleColor.Green;
                Console.WriteLine($"Diff: {ntpResult.TimeDifference}"); // a normal diff should be within less than half a second +-

                Console.ResetColor();
            }
            finally
            {
                Console.WriteLine($"{Environment.NewLine}DONE");
            }
        }
    }
}

License

MIT

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net5.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on ByronAP.Net.Ntp:

Package Downloads
invoisys.SDK.Time

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.4.2 457 8/23/2021