javascript grpc timestamp 1

javascript grpc timestamp

const timestamp = google.protobuf.Timestamp.fromObject({
  seconds: timeMS / 1000,
  nanos: (timeMS % 1000) * 1e6
})

Here is what the above code is Doing:
1. We’re importing the google.protobuf.Timestamp class from the protobuf library.
2. We’re creating a new instance of the Timestamp class.
3. We’re passing in an object with two properties: seconds and nanos.
4. The seconds property is the number of seconds since the Unix epoch.
5. The nanos property is the number of nanoseconds since the Unix epoch.
6. We’re using the Math.floor() function to round down the number of seconds.
7. We’re using the % (modulo) operator to get the remainder of the seconds.
8. We’re multiplying the remainder by 1e6 to convert it to nanoseconds.

Similar Posts