Class TimeExtensions (3.23.0)

public static class TimeExtensions

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

Inheritance

object > TimeExtensions

Namespace

Google.Protobuf.WellKnownTypes

Assembly

Google.Protobuf.dll

Methods

ToDuration(TimeSpan)

public static Duration ToDuration(this TimeSpan timeSpan)

Converts the given TimeSpan to a Duration.

Parameter
NameDescription
timeSpanTimeSpan

The time span to convert.

Returns
TypeDescription
Duration

The converted duration.

ToTimestamp(DateTime)

public static Timestamp ToTimestamp(this DateTime dateTime)

Converts the given DateTime to a Timestamp.

Parameter
NameDescription
dateTimeDateTime

The date and time to convert to a timestamp.

Returns
TypeDescription
Timestamp

The converted timestamp.

Exceptions
TypeDescription
ArgumentException

The dateTime value has a Kindother than Utc.

ToTimestamp(DateTimeOffset)

public static Timestamp ToTimestamp(this DateTimeOffset dateTimeOffset)

Converts the given DateTimeOffset to a Timestamp

Parameter
NameDescription
dateTimeOffsetDateTimeOffset

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

Returns
TypeDescription
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.