NtpClient
Ecng.Common
Provides functionality to retrieve time from a remote NTP server.
コンストラクター
NtpClient
public NtpClient(EndPoint ntpServer)
ntpClient = NtpClient(ntpServer)
Provides functionality to retrieve time from a remote NTP server.
- ntpServer
- The endpoint of the NTP server.
NtpClient
public NtpClient(string ntpServer)
ntpClient = NtpClient(ntpServer)
Initializes a new instance of the NtpClient class using the NTP server address.
- ntpServer
- The NTP server address in the format "hostname:port". Default is "time-a.nist.gov:123".
メソッド
GetLocalTime
public DateTime GetLocalTime(TimeZoneInfo info, int timeout)
result = ntpClient.GetLocalTime(info, timeout)
Retrieves the local time based on the specified time zone.
- info
- The time zone information.
- timeout
- The timeout in milliseconds for the NTP request. Default is 5000ms.
戻り値: The local time adjusted to the specified time zone.
GetLocalTimeAsync
public Task<DateTime> GetLocalTimeAsync(TimeZoneInfo info, int timeout, CancellationToken cancellationToken)
result = ntpClient.GetLocalTimeAsync(info, timeout, cancellationToken)
Retrieves the local time asynchronously based on the specified time zone.
GetUtcTime
public DateTime GetUtcTime(int timeout)
result = ntpClient.GetUtcTime(timeout)
Retrieves the UTC time from the NTP server.
- timeout
- The timeout in milliseconds for the NTP request. Default is 5000ms.
戻り値: The UTC time as provided by the NTP server.
GetUtcTimeAsync
public Task<DateTime> GetUtcTimeAsync(int timeout, CancellationToken cancellationToken)
result = ntpClient.GetUtcTimeAsync(timeout, cancellationToken)
Retrieves the UTC time from the NTP server asynchronously.