Search Results for

    Show / Hide Table of Contents

    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
    System.Object
    NetworkTimeProtocol
    Namespace: FM.LiveSwitch
    Assembly: FM.LiveSwitch.dll
    Syntax
    public class NetworkTimeProtocol : object

    Constructors

    NetworkTimeProtocol()

    Initializes a new instance of the NetworkTimeProtocol class with base set to 1900-01-01.

    Declaration
    public NetworkTimeProtocol()

    NetworkTimeProtocol(Int64)

    Initializes a new instance of the NetworkTimeProtocol class.

    Declaration
    public NetworkTimeProtocol(long baseTicks)
    Parameters
    Type Name Description
    System.Int64 baseTicks

    The base ticks.

    Properties

    Absolute

    Gets an instance of NetworkTimeProtocol that uses 1900-01-01 as the reference date, for use cases where the absolute wall-clock time represented is important.

    Declaration
    public static NetworkTimeProtocol Absolute { get; }
    Property Value
    Type Description
    NetworkTimeProtocol

    Relative

    Gets an instance of NetworkTimeProtocol that uses zero as the reference date, for use cases where the time is relative to other times, and the reference time is not significant.

    Declaration
    public static NetworkTimeProtocol Relative { get; }
    Property Value
    Type Description
    NetworkTimeProtocol

    UtcNow

    Gets the current UTC time in NTP format.

    Declaration
    public long UtcNow { get; }
    Property Value
    Type Description
    System.Int64

    Methods

    CompactNtpToDateTime(Int64)

    Converts a compact NTP timestamp (32 bits) to a date.

    Declaration
    public DateTime CompactNtpToDateTime(long ntp)
    Parameters
    Type Name Description
    System.Int64 ntp

    The NTP timestamp to convert.

    Returns
    Type Description
    DateTime

    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.Int64 ntp

    The NTP timestamp to convert.

    Returns
    Type Description
    System.Int64

    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
    DateTime dateTime

    The date to convert.

    Returns
    Type Description
    System.Int64

    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
    DateTime dateTime

    The date to convert.

    Returns
    Type Description
    System.Int64

    The equivalent NTP timestamp.

    DateTimeToNtpSeconds(DateTime)

    Converts a date to an NTP timestamp (double).

    Declaration
    public double DateTimeToNtpSeconds(DateTime dateTime)
    Parameters
    Type Name Description
    DateTime dateTime

    The date to convert.

    Returns
    Type Description
    System.Double

    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.Double ntpSeconds

    The NTP timestamp to convert.

    Returns
    Type Description
    DateTime

    The equivalent date.

    NtpSecondsToTicks(Double)

    Converts an NTP timestamp (double) to ticks.

    Declaration
    public long NtpSecondsToTicks(double ntpSeconds)
    Parameters
    Type Name Description
    System.Double ntpSeconds

    The NTP timestamp to convert.

    Returns
    Type Description
    System.Int64

    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.Int64 ntp

    The NTP timestamp to convert.

    Returns
    Type Description
    DateTime

    The equivalent date.

    NtpToTicks(Int64)

    Converts an NTP timestamp (64 bits) to ticks.

    Declaration
    public long NtpToTicks(long ntp)
    Parameters
    Type Name Description
    System.Int64 ntp

    The NTP timestamp to convert.

    Returns
    Type Description
    System.Int64

    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.Int64 ticks

    The ticks to convert.

    Returns
    Type Description
    System.Int64

    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.Int64 ticks

    The ticks to convert.

    Returns
    Type Description
    System.Int64

    The equivalent NTP timestamp.

    TicksToNtpSeconds(Int64)

    Converts ticks to an NTP timestamp (double).

    Declaration
    public double TicksToNtpSeconds(long ticks)
    Parameters
    Type Name Description
    System.Int64 ticks

    The ticks to convert.

    Returns
    Type Description
    System.Double

    The equivalent NTP timestamp.

    In This Article
    Back to top Copyright © LiveSwitch Inc. All Rights Reserved. Doc build for LiveSwitch v1.15.0