Show / Hide Table of Contents

Class TimeExtensions

Extension methods on BCL time-related types, converting to protobuf types.

Inheritance
System.Object
TimeExtensions
Inherited Members
System.Object.ToString()
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
Namespace: Google.Protobuf.WellKnownTypes
Assembly: Google.Protobuf.dll
Syntax
public static class TimeExtensions

Methods

ToDuration(TimeSpan)

Converts the given System.TimeSpan to a Duration.

Declaration
public static Duration ToDuration(this TimeSpan timeSpan)
Parameters
Type Name Description
System.TimeSpan timeSpan

The time span to convert.

Returns
Type Description
Duration

The converted duration.

ToTimestamp(DateTime)

Converts the given System.DateTime to a Timestamp.

Declaration
public static Timestamp ToTimestamp(this DateTime dateTime)
Parameters
Type Name Description
System.DateTime dateTime

The date and time to convert to a timestamp.

Returns
Type Description
Timestamp

The converted timestamp.

Exceptions
Type Condition
System.ArgumentException

The dateTime value has a System.DateTime.Kindother than Utc.

ToTimestamp(DateTimeOffset)

Converts the given System.DateTimeOffset to a Timestamp

Declaration
public static Timestamp ToTimestamp(this DateTimeOffset dateTimeOffset)
Parameters
Type Name Description
System.DateTimeOffset dateTimeOffset

The date and time (with UTC offset) to convert to a timestamp.

Returns
Type Description
Timestamp

The converted timestamp.

Remarks

The offset is taken into consideration when converting the value (so the same instant in time is represented) but is not a separate part of the resulting value. In other words, there is no roundtrip operation to retrieve the original DateTimeOffset.

Back to top