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.
Inherited Members
Namespace: Google.Cloud.Firestore
Assembly: Google.Cloud.Firestore.dll
Syntax
public struct Timestamp : IEquatable<Timestamp>, IComparable, IComparable<Timestamp>
Methods
CompareTo(Timestamp)
Declaration
public int CompareTo(Timestamp other)
Parameters
Type | Name | Description |
---|---|---|
Timestamp | other |
Returns
Type | Description |
---|---|
int |
Implements
CompareTo(object)
Declaration
public int CompareTo(object obj)
Parameters
Type | Name | Description |
---|---|---|
object | obj |
Returns
Type | Description |
---|---|
int |
Implements
FromDateTime(DateTime)
Declaration
public static Timestamp FromDateTime(DateTime dateTime)
Parameters
Type | Name | Description |
---|---|---|
DateTime | dateTime | The value to convert; its kind must be Utc. |
Returns
Type | Description |
---|---|
Timestamp | A Timestamp representation of |
FromDateTimeOffset(DateTimeOffset)
Converts the given DateTimeOffset to a Timestamp
Declaration
public static Timestamp FromDateTimeOffset(DateTimeOffset dateTimeOffset)
Parameters
Type | 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
.
FromProto(Timestamp)
Creates an instance from a Protobuf Timestamp representation. Later modifications to the Protobuf representation will not affect the returned oject.
Declaration
public static Timestamp FromProto(Timestamp proto)
Parameters
Type | Name | Description |
---|---|---|
Timestamp | proto | A Protobuf timestamp representation. Must not be null. |
Returns
Type | Description |
---|---|
Timestamp | An immutable timestamp. |
GetCurrentTimestamp()
Returns the current timestamp according to the system clock. The system time zone is irrelevant, as a timestamp represents an instant in time.
Declaration
public static Timestamp GetCurrentTimestamp()
Returns
Type | Description |
---|---|
Timestamp | The current timestamp according to the system clock. |
GetHashCode()
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
int |
Overrides
ToDateTime()
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.
Declaration
public DateTime ToDateTime()
Returns
Type | Description |
---|---|
DateTime | A DateTime representation of this timestamp. |
ToDateTimeOffset()
Converts this timestamp into a DateTimeOffset.
Declaration
public DateTimeOffset ToDateTimeOffset()
Returns
Type | Description |
---|---|
DateTimeOffset | This timestamp as a |
Remarks
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()
Creates a Protobuf Timestamp representation of this timestamp. Modifications to the returned message will not be reflected in this object.
Declaration
public Timestamp ToProto()
Returns
Type | Description |
---|---|
Timestamp | A Protobuf timestamp representation. |
ToString()
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
string |
Overrides
Operators
operator ==(Timestamp, Timestamp)
Operator overload to compare two Blob values for equality.
Declaration
public static bool operator ==(Timestamp lhs, Timestamp rhs)
Parameters
Type | Name | Description |
---|---|---|
Timestamp | lhs | Left value to compare |
Timestamp | rhs | Right value to compare |
Returns
Type | Description |
---|---|
bool | true if |
operator >(Timestamp, Timestamp)
Compares two timestamps.
Declaration
public static bool operator >(Timestamp lhs, Timestamp rhs)
Parameters
Type | Name | Description |
---|---|---|
Timestamp | lhs | The left timestamp to compare. |
Timestamp | rhs | The right timestamp to compare. |
Returns
Type | Description |
---|---|
bool | true is |
operator >=(Timestamp, Timestamp)
Compares two timestamps.
Declaration
public static bool operator >=(Timestamp lhs, Timestamp rhs)
Parameters
Type | Name | Description |
---|---|---|
Timestamp | lhs | The left timestamp to compare. |
Timestamp | rhs | The right timestamp to compare. |
Returns
Type | Description |
---|---|
bool | true is |
operator !=(Timestamp, Timestamp)
Operator overload to compare two Blob values for inequality.
Declaration
public static bool operator !=(Timestamp lhs, Timestamp rhs)
Parameters
Type | Name | Description |
---|---|---|
Timestamp | lhs | Left value to compare |
Timestamp | rhs | Right value to compare |
Returns
Type | Description |
---|---|
bool | false if |
operator <(Timestamp, Timestamp)
Compares two timestamps.
Declaration
public static bool operator <(Timestamp lhs, Timestamp rhs)
Parameters
Type | Name | Description |
---|---|---|
Timestamp | lhs | The left timestamp to compare. |
Timestamp | rhs | The right timestamp to compare. |
Returns
Type | Description |
---|---|
bool | true is |
operator <=(Timestamp, Timestamp)
Compares two timestamps.
Declaration
public static bool operator <=(Timestamp lhs, Timestamp rhs)
Parameters
Type | Name | Description |
---|---|---|
Timestamp | lhs | The left timestamp to compare. |
Timestamp | rhs | The right timestamp to compare. |
Returns
Type | Description |
---|---|
bool | true is |