how to use FieldValue.serverTimestamp() to custom model class in android
Date : March 29 2020, 07:55 AM
I wish this helpful for you I am using Firestore as a database and now i want to store server timestamp when user register. , After lots of research i found a solution for this. @ServerTimestamp
private Date timestamp;
public Date getTimestamp() {
return timestamp;
}
public void setTimestamp(Date timestamp) {
this.timestamp = timestamp;
}
UserModel userModel = new UserModel();
userModel.setEmail(email);
userModel.setPassword(password);
userModel.setName(name);
userModel.setUid(uid);
insertUserDataToFireStore(userModel);
|
How to get a JavaScript Date object from the new `firebase.firestore.FieldValue.serverTimestamp()`
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further Firebase Firestore recently changed how they manage timestamps, and I'm unable to retrieve a date object from the timestamp. , You just need to do this: yourFirestoreTimestamp.toDate()
|
Function FieldValue.arrayUnion() called with invalid data. FieldValue.serverTimestamp() can only be used with update() a
Tag : arrays , By : user126922
Date : March 29 2020, 07:55 AM
I hope this helps you . You can't use FieldValue.serverTimestamp() as the value to union (add) or remove, to or from, an array type value of a document field. If you want to use that timestamp value, you need to pass it directly to a field you're updating or setting. You'll have to think of another way you structure your data that meets your needs and also satisfies Firestore requirements.
|
How to use FieldValue.serverTimestamp() as Model class in iOS - swift
Tag : ios , By : Felix Almeida
Date : March 29 2020, 07:55 AM
I wish this help you Try this: assume we have a Firestore structure of this (as shown in the Firestore console) timestamps
stamp_0
stamp: September 18, 2018 at 8:00:00 AM UTC-4
stamp_1
stamp: September 18, 2018 at 8:01:00 AM UTC-4
stamp_2
stamp: September 18, 2018 at 8:02:00 AM UTC-4
self.db.collection("timestamps").getDocuments() { (querySnapshot, err) in
if let err = err {
print("Error getting documents: \(err)")
} else {
for document in querySnapshot!.documents {
if let stamp = document.get("stamp") {
let title = document.documentID
let ts = stamp as! Timestamp
let aDate = ts.dateValue()
let formatter = DateFormatter()
formatter.dateFormat = "yyyy-MM-dd HH:mm:ss ZZZ"
let formattedTimeZoneStr = formatter.string(from: aDate)
print(title, formattedTimeZoneStr)
}
}
}
}
stamp_0 2018-09-18 08:00:00 -0400
stamp_1 2018-09-18 08:01:00 -0400
stamp_2 2018-09-18 08:02:00 -0400
|
Difference between using FieldValue.serverTimestamp and Date.now
Date : March 29 2020, 07:55 AM
hope this fix your issue If you write Date.now() from the client into the database, you're writing the client-side timestamp. If on the other hand you write firestore.FieldValue.serverTimestamp, it ends up writing the server-side timestamp. There are a few types of changes between the two:
|