Class NtpClient
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
EndPointThe 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
stringThe 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
TimeZoneInfoThe time zone information.
timeout
intThe 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
intThe timeout in milliseconds for the NTP request. Default is 5000ms.
Returns
- DateTime
The UTC time as provided by the NTP server.