A Timestamp represents a point in time independent of any time zone orcalendar, represented as seconds and fractions of seconds at nanosecondresolution in UTC Epoch time.

It is encoded using the Proleptic GregorianCalendar which extends the Gregorian calendar backwards to year one. It isencoded assuming all minutes are 60 seconds long, i.e. leap seconds are"smeared" so that no leap second table is needed for interpretation. Range isfrom 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z.

see

https://github.com/google/protobuf/blob/master/src/google/protobuf/timestamp.proto

Index

Constructors

constructor

  • newTimestamp(secondsnumber, nanosecondsnumber):Timestamp
  • Creates a new timestamp.

    Parameters

    • seconds:number

      The number of seconds of UTC time since Unix epoch1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to9999-12-31T23:59:59Z inclusive.

    • nanoseconds:number

      The non-negative fractions of a second at nanosecondresolution. Negative second values with fractions must still havenon-negative nanoseconds values that count forward in time. Must befrom 0 to 999,999,999 inclusive.

    ReturnsTimestamp

Properties

nanoseconds

nanoseconds:number

seconds

seconds:number

Methods

isEqual

  • isEqual(otherTimestamp):boolean
  • Returns true if thisTimestamp is equal to the provided one.

    Parameters

    • other:Timestamp

      TheTimestamp to compare against.

    Returnsboolean

    true if thisTimestamp is equal to the provided one.

toDate

  • toDate():Date
  • Convert a Timestamp to a JavaScriptDate object. This conversion causesa loss of precision sinceDate objects only support millisecond precision.

    ReturnsDate

    JavaScriptDate object representing the same point in time asthisTimestamp, with millisecond precision.

toMillis

  • toMillis():number
  • Convert a timestamp to a numeric timestamp (in milliseconds since epoch).This operation causes a loss of precision.

    Returnsnumber

    The point in time corresponding to this timestamp, represented asthe number of milliseconds since Unix epoch 1970-01-01T00:00:00Z.

valueOf

  • valueOf():string
  • Converts this object to a primitive string, which allows Timestamp objects to be comparedusing the>,<=,>= and> operators.

    Returnsstring

Static fromDate

  • fromDate(dateDate):Timestamp
  • Creates a new timestamp from the given date.

    Parameters

    • date:Date

      The date to initialize theTimestamp from.

    ReturnsTimestamp

    A newTimestamp representing the same point in time as the givendate.

Static fromMillis

  • fromMillis(millisecondsnumber):Timestamp
  • Creates a new timestamp from the given number of milliseconds.

    Parameters

    • milliseconds:number

      Number of milliseconds since Unix epoch1970-01-01T00:00:00Z.

    ReturnsTimestamp

    A newTimestamp representing the same point in time as the givennumber of milliseconds.

Static now

  • now():Timestamp
  • Creates a new timestamp with the current date, with millisecond precision.

    ReturnsTimestamp

    a new timestamp representing the current date.

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2022-07-27 UTC.