0

In one of my projects, I want to store application start time and end time to GCP Firestore in timestamp format.

I have tried the following things

  1. I tried to save the java DateTime but in the Firestore its storing as array(Firestore screenshot).enter image description here

  2. and also I tried to use the FieldValue but it's storing start time and end time as the same. enter image description here

is there any way I can store time stamp in GCP Firestore with the actual time difference(application start time and end time)

I am storing the below model class by updating the completeAt and startedAt fields(note: I have tried with type FieldValue as well instead of Date).

public class Test{
 private Date completeAt
private Date completeAt
}
Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
reddy
  • 79
  • 1
  • 11

1 Answers1

0

Regarding the first attempt, completeAt it's not an array, it's an object.

Regarding your second attempt:

Is there any way I can store time stamp in GCP Firestore with the actual time difference(application start time and end time)

Both fields completeAt and startedAt are populated with the correct data type. However, the values are not correct. If you want the startedAt field to hold a Timestamp value when the app starts, then you should perform an update operation right then. As soon as the user stops using the app, perform another update the add the corresponding Timestamp to the completeAt field. In this way, you'll have different values for each field.

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193