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.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-07 UTC."],[[["\u003cp\u003eThe \u003ccode\u003eTimeExtensions\u003c/code\u003e class provides extension methods for converting between BCL time-related types and protobuf types, specifically \u003ccode\u003eTimeSpan\u003c/code\u003e, \u003ccode\u003eDateTime\u003c/code\u003e, and \u003ccode\u003eDateTimeOffset\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eToDuration\u003c/code\u003e method converts a \u003ccode\u003eTimeSpan\u003c/code\u003e to a \u003ccode\u003eDuration\u003c/code\u003e protobuf type.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eToTimestamp\u003c/code\u003e method can convert either a \u003ccode\u003eDateTime\u003c/code\u003e or a \u003ccode\u003eDateTimeOffset\u003c/code\u003e into a \u003ccode\u003eTimestamp\u003c/code\u003e protobuf type.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eToTimestamp\u003c/code\u003e method for \u003ccode\u003eDateTime\u003c/code\u003e values will throw an \u003ccode\u003eArgumentException\u003c/code\u003e if the \u003ccode\u003eKind\u003c/code\u003e is not set to \u003ccode\u003eUtc\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eWhen converting \u003ccode\u003eDateTimeOffset\u003c/code\u003e to \u003ccode\u003eTimestamp\u003c/code\u003e, the offset is considered during the conversion process, but the original offset cannot be retrieved after the conversion.\u003c/p\u003e\n"]]],[],null,["# Class TimeExtensions (3.27.1)\n\nVersion latestkeyboard_arrow_down\n\n- [3.27.1 (latest)](/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.WellKnownTypes.TimeExtensions)\n- [3.23.0](/dotnet/docs/reference/Google.Protobuf/3.23.0/Google.Protobuf.WellKnownTypes.TimeExtensions)\n- [3.15.8](/dotnet/docs/reference/Google.Protobuf/3.15.8/Google.Protobuf.WellKnownTypes.TimeExtensions) \n\n public static class TimeExtensions\n\nExtension methods on BCL time-related types, converting to protobuf types. \n\nInheritance\n-----------\n\n[object](https://learn.microsoft.com/dotnet/api/system.object) \\\u003e TimeExtensions \n\nInherited Members\n-----------------\n\n[object.Equals(object)](https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object)) \n[object.Equals(object, object)](https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object-system-object)) \n[object.GetHashCode()](https://learn.microsoft.com/dotnet/api/system.object.gethashcode) \n[object.GetType()](https://learn.microsoft.com/dotnet/api/system.object.gettype) \n[object.MemberwiseClone()](https://learn.microsoft.com/dotnet/api/system.object.memberwiseclone) \n[object.ReferenceEquals(object, object)](https://learn.microsoft.com/dotnet/api/system.object.referenceequals) \n[object.ToString()](https://learn.microsoft.com/dotnet/api/system.object.tostring)\n\nNamespace\n---------\n\n[Google.Protobuf.WellKnownTypes](/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.WellKnownTypes)\n\nAssembly\n--------\n\nGoogle.Protobuf.dll\n\nMethods\n-------\n\n### ToDuration(TimeSpan)\n\n public static Duration ToDuration(this TimeSpan timeSpan)\n\nConverts the given [TimeSpan](https://learn.microsoft.com/dotnet/api/system.timespan) to a [Duration](/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.WellKnownTypes.Duration).\n\n### ToTimestamp(DateTime)\n\n public static Timestamp ToTimestamp(this DateTime dateTime)\n\nConverts the given [DateTime](https://learn.microsoft.com/dotnet/api/system.datetime) to a [Timestamp](/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.WellKnownTypes.Timestamp).\n\n### ToTimestamp(DateTimeOffset)\n\n public static Timestamp ToTimestamp(this DateTimeOffset dateTimeOffset)\n\nConverts the given [DateTimeOffset](https://learn.microsoft.com/dotnet/api/system.datetimeoffset) to a [Timestamp](/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.WellKnownTypes.Timestamp)\n\n**Remarks** \nThe offset is taken into consideration when converting the value (so the same instant in time\nis represented) but is not a separate part of the resulting value. In other words, there is no\nroundtrip operation to retrieve the original `DateTimeOffset`."]]