Class NetworkTimeProtocol
Utility class to assist with Network Time Protocol (NTP) conversions. NTP timestamps are 64-bit values that can span just over 136 years, from 1900-01-01 to 2036-02-08. Compact NTP timestamps are 32-bit values that can span span just over 18 hours. These utility methods guarantee precision to the millisecond.
Inheritance
Namespace: FM.LiveSwitch
Assembly: FM.LiveSwitch.dll
Syntax
public class NetworkTimeProtocol : object
Constructors
NetworkTimeProtocol()
Initializes a new instance of the Network
Declaration
public NetworkTimeProtocol()
NetworkTimeProtocol(Int64)
Initializes a new instance of the Network
Declaration
public NetworkTimeProtocol(long baseTicks)
Parameters
Type | Name | Description |
---|---|---|
System. |
baseTicks | The base ticks. |
Properties
Absolute
Gets an instance of Network
Declaration
public static NetworkTimeProtocol Absolute { get; }
Property Value
Type | Description |
---|---|
Network |
Relative
Gets an instance of Network
Declaration
public static NetworkTimeProtocol Relative { get; }
Property Value
Type | Description |
---|---|
Network |
UtcNow
Gets the current UTC time in NTP format.
Declaration
public long UtcNow { get; }
Property Value
Type | Description |
---|---|
System. |
Methods
CompactNtpToDateTime(Int64)
Converts a compact NTP timestamp (32 bits) to a date.
Declaration
public DateTime CompactNtpToDateTime(long ntp)
Parameters
Type | Name | Description |
---|---|---|
System. |
ntp | The NTP timestamp to convert. |
Returns
Type | Description |
---|---|
Date |
The equivalent date. |
CompactNtpToTicks(Int64)
Converts a compact NTP timestamp (32 bits) to ticks.
Declaration
public long CompactNtpToTicks(long ntp)
Parameters
Type | Name | Description |
---|---|---|
System. |
ntp | The NTP timestamp to convert. |
Returns
Type | Description |
---|---|
System. |
The equivalent ticks. |
DateTimeToCompactNtp(DateTime)
Converts a date to a compact NTP timestamp (32 bits).
Declaration
public long DateTimeToCompactNtp(DateTime dateTime)
Parameters
Type | Name | Description |
---|---|---|
Date |
dateTime | The date to convert. |
Returns
Type | Description |
---|---|
System. |
The equivalent NTP timestamp. |
DateTimeToNtp(DateTime)
Converts a date to an NTP timestamp (64 bits).
Declaration
public long DateTimeToNtp(DateTime dateTime)
Parameters
Type | Name | Description |
---|---|---|
Date |
dateTime | The date to convert. |
Returns
Type | Description |
---|---|
System. |
The equivalent NTP timestamp. |
DateTimeToNtpSeconds(DateTime)
Converts a date to an NTP timestamp (double).
Declaration
public double DateTimeToNtpSeconds(DateTime dateTime)
Parameters
Type | Name | Description |
---|---|---|
Date |
dateTime | The date to convert. |
Returns
Type | Description |
---|---|
System. |
The equivalent NTP timestamp. |
NtpSecondsToDateTime(Double)
Converts an NTP timestamp (double) to a date.
Declaration
public DateTime NtpSecondsToDateTime(double ntpSeconds)
Parameters
Type | Name | Description |
---|---|---|
System. |
ntpSeconds | The NTP timestamp to convert. |
Returns
Type | Description |
---|---|
Date |
The equivalent date. |
NtpSecondsToTicks(Double)
Converts an NTP timestamp (double) to ticks.
Declaration
public long NtpSecondsToTicks(double ntpSeconds)
Parameters
Type | Name | Description |
---|---|---|
System. |
ntpSeconds | The NTP timestamp to convert. |
Returns
Type | Description |
---|---|
System. |
The equivalent ticks. |
NtpToDateTime(Int64)
Converts an NTP timestamp (64 bits) to a date.
Declaration
public DateTime NtpToDateTime(long ntp)
Parameters
Type | Name | Description |
---|---|---|
System. |
ntp | The NTP timestamp to convert. |
Returns
Type | Description |
---|---|
Date |
The equivalent date. |
NtpToTicks(Int64)
Converts an NTP timestamp (64 bits) to ticks.
Declaration
public long NtpToTicks(long ntp)
Parameters
Type | Name | Description |
---|---|---|
System. |
ntp | The NTP timestamp to convert. |
Returns
Type | Description |
---|---|
System. |
The equivalent ticks. |
TicksToCompactNtp(Int64)
Converts ticks to a compact NTP timestamp (32 bits).
Declaration
public long TicksToCompactNtp(long ticks)
Parameters
Type | Name | Description |
---|---|---|
System. |
ticks | The ticks to convert. |
Returns
Type | Description |
---|---|
System. |
The equivalent NTP timestamp. |
TicksToNtp(Int64)
Converts ticks to an NTP timestamp (64 bits).
Declaration
public long TicksToNtp(long ticks)
Parameters
Type | Name | Description |
---|---|---|
System. |
ticks | The ticks to convert. |
Returns
Type | Description |
---|---|
System. |
The equivalent NTP timestamp. |
TicksToNtpSeconds(Int64)
Converts ticks to an NTP timestamp (double).
Declaration
public double TicksToNtpSeconds(long ticks)
Parameters
Type | Name | Description |
---|---|---|
System. |
ticks | The ticks to convert. |
Returns
Type | Description |
---|---|
System. |
The equivalent NTP timestamp. |