Table of Contents

Class NtpClient

Namespace
Ecng.Common
Assembly
Ecng.Common.dll

Provides functionality to retrieve time from a remote NTP server.

public class NtpClient
Inheritance
NtpClient
Inherited Members
Extension Methods

Constructors

NtpClient(EndPoint)

Provides functionality to retrieve time from a remote NTP server.

public NtpClient(EndPoint ntpServer)

Parameters

ntpServer EndPoint

The endpoint of the NTP server.

NtpClient(string)

Initializes a new instance of the NtpClient class using the NTP server address.

public NtpClient(string ntpServer = "time-a.nist.gov:123")

Parameters

ntpServer string

The NTP server address in the format "hostname:port". Default is "time-a.nist.gov:123".

Methods

GetLocalTime(TimeZoneInfo, int)

Retrieves the local time based on the specified time zone.

public DateTime GetLocalTime(TimeZoneInfo info, int timeout = 5000)

Parameters

info TimeZoneInfo

The time zone information.

timeout int

The timeout in milliseconds for the NTP request. Default is 5000ms.

Returns

DateTime

The local time adjusted to the specified time zone.

Exceptions

ArgumentNullException

Thrown when info is null.

GetUtcTime(int)

Retrieves the UTC time from the NTP server.

public DateTime GetUtcTime(int timeout = 5000)

Parameters

timeout int

The timeout in milliseconds for the NTP request. Default is 5000ms.

Returns

DateTime

The UTC time as provided by the NTP server.