Class TimeExtensions (3.15.8)

public static class TimeExtensions : object

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 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 to a Timestamp.

Parameter
NameDescription
dateTimeDateTime

The date and time to convert to a timestamp.

Returns
TypeDescription
Timestamp

The converted timestamp.

ToTimestamp(DateTimeOffset)

public static Timestamp ToTimestamp(this DateTimeOffset dateTimeOffset)

Converts the given 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.