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
Name Description
timeSpan TimeSpan

The time span to convert.

Returns
Type Description
Duration

The converted duration.

ToTimestamp(DateTime)

public static Timestamp ToTimestamp(this DateTime dateTime)

Converts the given DateTime to a Timestamp.

Parameter
Name Description
dateTime DateTime

The date and time to convert to a timestamp.

Returns
Type Description
Timestamp

The converted timestamp.

Exceptions
Type Description
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
Name Description
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.