简体   繁体   中英

How can I implement Firestore timestamp in Spring Boot Application

I am creating a Spring Boot application and I have a timestamp variable in Firestore DB I want to send date in that field. How can I do that?

这是来自我的 Firebase DB 我使用 dob 作为时间戳

这是我用来从数据库调用时间戳的数据类型,但这是错误的我无法发送正确的日期

This is my service I am sending data to Firebase

    public Patient addPatient(Patient patients) throws InterruptedException, ExecutionException  {
    
    Firestore dbFirestore = FirestoreClient.getFirestore();
    ApiFuture<WriteResult> collectionApiResult = dbFirestore.collection(this.fireStoreCollection).document(patients.getUserId()).set(patients);
    return patients;
}

我的 Firestore DB 屏幕截图我想在此发送 dob

As mentioned by @Zeenath SN above, this post has your answer.

You can use ServerTimestamp annotation. Try changing

private Timestamp dob;

to

private Date dob;

in your code.

Alternatively, as below:

If you want to write a timestamp field, and you can't use a server timestamp, you will need to either provide a regular Java Date object, or a Firebase Timestamp object. Either of these types of values will convert to a timestamp field in the document.

When you query for the document, the field will always show up in the document snapshot as a Timestamp type object.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM