public struct Timestamp : IEquatable<Timestamp>, IComparable, IComparable<Timestamp>
Reference documentation and code samples for the Firestore API struct Timestamp.
A nanosecond-precision immutable timestamp. When this is stored as part of a document in Firestore,
it is truncated to the microsecond, towards the start of time.
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.
FromProto(Timestamp)
public static Timestamp FromProto(Timestamp proto)
Creates an instance from a Protobuf Timestamp representation.
Later modifications to the Protobuf representation will not affect the returned oject.
Converts this timestamp to a DateTime with a kind of
Utc. This can lose information as DateTime has a precision of
a tick (100 nanoseconds). If the timestamp is not a precise number of ticks, it will be
truncated towards the start of time.
The resulting DateTimeOffset will always have an Offset of zero.
If the timestamp is not a precise number of ticks, it will be truncated towards the start
of time.
DateTimeOffset value precisely on a second.
ToProto()
public Timestamp ToProto()
Creates a Protobuf Timestamp representation of this
timestamp. Modifications to the returned message will not be reflected in this object.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-07 UTC."],[[["\u003cp\u003eThe latest version of the Firestore API Timestamp struct is 3.10.0, with various other versions available for reference, ranging down to version 2.3.1.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eTimestamp\u003c/code\u003e struct provides a nanosecond-precision immutable timestamp, which when stored in Firestore is truncated to the microsecond.\u003c/p\u003e\n"],["\u003cp\u003eThis struct implements \u003ccode\u003eIEquatable<Timestamp>\u003c/code\u003e, \u003ccode\u003eIComparable\u003c/code\u003e, and \u003ccode\u003eIComparable<Timestamp>\u003c/code\u003e, enabling comparisons and equality checks, as well as providing many comparison operators.\u003c/p\u003e\n"],["\u003cp\u003eIt offers methods for conversion to and from \u003ccode\u003eDateTime\u003c/code\u003e, \u003ccode\u003eDateTimeOffset\u003c/code\u003e, and Protobuf \u003ccode\u003eTimestamp\u003c/code\u003e representations.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eTimestamp\u003c/code\u003e struct can retrieve the current timestamp from the system clock with the method \u003ccode\u003eGetCurrentTimestamp()\u003c/code\u003e.\u003c/p\u003e\n"]]],[],null,["# Firestore API - Struct Timestamp (3.10.0)\n\nVersion latestkeyboard_arrow_down\n\n- [3.10.0 (latest)](/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.Timestamp)\n- [3.9.0](/dotnet/docs/reference/Google.Cloud.Firestore/3.9.0/Google.Cloud.Firestore.Timestamp)\n- [3.8.0](/dotnet/docs/reference/Google.Cloud.Firestore/3.8.0/Google.Cloud.Firestore.Timestamp)\n- [3.7.0](/dotnet/docs/reference/Google.Cloud.Firestore/3.7.0/Google.Cloud.Firestore.Timestamp)\n- [3.6.0](/dotnet/docs/reference/Google.Cloud.Firestore/3.6.0/Google.Cloud.Firestore.Timestamp)\n- [3.5.1](/dotnet/docs/reference/Google.Cloud.Firestore/3.5.1/Google.Cloud.Firestore.Timestamp)\n- [3.4.0](/dotnet/docs/reference/Google.Cloud.Firestore/3.4.0/Google.Cloud.Firestore.Timestamp)\n- [3.3.0](/dotnet/docs/reference/Google.Cloud.Firestore/3.3.0/Google.Cloud.Firestore.Timestamp)\n- [3.2.0](/dotnet/docs/reference/Google.Cloud.Firestore/3.2.0/Google.Cloud.Firestore.Timestamp)\n- [3.1.0](/dotnet/docs/reference/Google.Cloud.Firestore/3.1.0/Google.Cloud.Firestore.Timestamp)\n- [3.0.0](/dotnet/docs/reference/Google.Cloud.Firestore/3.0.0/Google.Cloud.Firestore.Timestamp)\n- [2.5.0](/dotnet/docs/reference/Google.Cloud.Firestore/2.5.0/Google.Cloud.Firestore.Timestamp)\n- [2.4.0](/dotnet/docs/reference/Google.Cloud.Firestore/2.4.0/Google.Cloud.Firestore.Timestamp)\n- [2.3.1](/dotnet/docs/reference/Google.Cloud.Firestore/2.3.1/Google.Cloud.Firestore.Timestamp) \n\n public struct Timestamp : IEquatable\u003cTimestamp\u003e, IComparable, IComparable\u003cTimestamp\u003e\n\nReference documentation and code samples for the Firestore API struct Timestamp.\n\nA nanosecond-precision immutable timestamp. When this is stored as part of a document in Firestore,\nit is truncated to the microsecond, towards the start of time. \n\nImplements\n----------\n\n[IEquatable](https://learn.microsoft.com/dotnet/api/system.iequatable-1)[Timestamp](/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.Timestamp), [IComparable](https://learn.microsoft.com/dotnet/api/system.icomparable), [IComparable](https://learn.microsoft.com/dotnet/api/system.icomparable-1)[Timestamp](/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.Timestamp) \n\nInherited Members\n-----------------\n\n[object.GetType()](https://learn.microsoft.com/dotnet/api/system.object.gettype)\n\nNamespace\n---------\n\n[Google.Cloud.Firestore](/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore)\n\nAssembly\n--------\n\nGoogle.Cloud.Firestore.dll\n\nMethods\n-------\n\n### CompareTo(Timestamp)\n\n public int CompareTo(Timestamp other)\n\n### CompareTo(object)\n\n public int CompareTo(object obj)\n\n### FromDateTime(DateTime)\n\n public static Timestamp FromDateTime(DateTime dateTime)\n\nConverts a [DateTime](https://learn.microsoft.com/dotnet/api/system.datetime) to a [Timestamp](/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.Timestamp).\n\n### FromDateTimeOffset(DateTimeOffset)\n\n public static Timestamp FromDateTimeOffset(DateTimeOffset dateTimeOffset)\n\nConverts the given [DateTimeOffset](https://learn.microsoft.com/dotnet/api/system.datetimeoffset) to a [Timestamp](/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.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`.\n\n### FromProto(Timestamp)\n\n public static Timestamp FromProto(Timestamp proto)\n\nCreates an instance from a Protobuf [Timestamp](https://cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.WellKnownTypes.Timestamp.html) representation.\nLater modifications to the Protobuf representation will not affect the returned oject.\n\n### GetCurrentTimestamp()\n\n public static Timestamp GetCurrentTimestamp()\n\nReturns the current timestamp according to the system clock. The system time zone\nis irrelevant, as a timestamp represents an instant in time.\n\n### GetHashCode()\n\n public override int GetHashCode()\n\n**Overrides** \n[ValueType.GetHashCode()](https://learn.microsoft.com/dotnet/api/system.valuetype.gethashcode)\n\n### ToDateTime()\n\n public DateTime ToDateTime()\n\nConverts this timestamp to a [DateTime](https://learn.microsoft.com/dotnet/api/system.datetime) with a kind of\n[Utc](https://learn.microsoft.com/dotnet/api/system.datetimekind#system-datetimekind-utc). This can lose information as DateTime has a precision of\na tick (100 nanoseconds). If the timestamp is not a precise number of ticks, it will be\ntruncated towards the start of time.\n\n### ToDateTimeOffset()\n\n public DateTimeOffset ToDateTimeOffset()\n\nConverts this timestamp into a [DateTimeOffset](https://learn.microsoft.com/dotnet/api/system.datetimeoffset).\n\n**Remarks** \nThe resulting `DateTimeOffset` will always have an `Offset` of zero.\nIf the timestamp is not a precise number of ticks, it will be truncated towards the start\nof time.\n[DateTimeOffset](https://learn.microsoft.com/dotnet/api/system.datetimeoffset) value precisely on a second.\n\n### ToProto()\n\n public Timestamp ToProto()\n\nCreates a Protobuf [Timestamp](https://cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.WellKnownTypes.Timestamp.html) representation of this\ntimestamp. Modifications to the returned message will not be reflected in this object.\n\n### ToString()\n\n public override string ToString()\n\n**Overrides** \n[ValueType.ToString()](https://learn.microsoft.com/dotnet/api/system.valuetype.tostring)\n\nOperators\n---------\n\n### operator ==(Timestamp, Timestamp)\n\n public static bool operator ==(Timestamp lhs, Timestamp rhs)\n\nOperator overload to compare two Blob values for equality.\n\n### operator \\\u003e(Timestamp, Timestamp)\n\n public static bool operator \u003e(Timestamp lhs, Timestamp rhs)\n\nCompares two timestamps.\n\n### operator \\\u003e=(Timestamp, Timestamp)\n\n public static bool operator \u003e=(Timestamp lhs, Timestamp rhs)\n\nCompares two timestamps.\n\n### operator !=(Timestamp, Timestamp)\n\n public static bool operator !=(Timestamp lhs, Timestamp rhs)\n\nOperator overload to compare two Blob values for inequality.\n\n### operator \\\u003c(Timestamp, Timestamp)\n\n public static bool operator \u003c(Timestamp lhs, Timestamp rhs)\n\nCompares two timestamps.\n\n### operator \\\u003c=(Timestamp, Timestamp)\n\n public static bool operator \u003c=(Timestamp lhs, Timestamp rhs)\n\nCompares two timestamps."]]