logo
down
shadow

How do I cast FieldValue.serverTimestamp() to Kotlin/Java Date Class


How do I cast FieldValue.serverTimestamp() to Kotlin/Java Date Class

Content Index :

How do I cast FieldValue.serverTimestamp() to Kotlin/Java Date Class
Tag : java , By : Jeskl
Date : January 11 2021, 05:14 PM

may help you . I want to save the date that a post was created in Firestore but I do not want to use the System time. Rather I want to use the server timestamp for accuracy sake. So I am using FieldValue.serverTimestamp() to get the server timestamp but the data type of my variable that holds this is Date. So How can I cast FieldValue.serverTimestamp() to Date? , You get the following error:
data class MyModel(
               @ServerTimestamp
               val timeStamp: Date? = null)

Comments
No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

how to use FieldValue.serverTimestamp() to custom model class in android


Tag : android , By : Phil Austin
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()`


Tag : javascript , By : Mena
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


Tag : firebase , By : onurtopcu
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:
Related Posts Related QUESTIONS :
  • How to iterate through array in order
  • Is there better way of iteration to find the evenly divisible number?
  • How do I avoid using if statements with a large amount of variables in java
  • Writing JUnit test cases for a Spring Boot Service Application with autowired components
  • Cors for GET with Postman not showing headers
  • Printing values in different column same row using APACHE POI
  • Fully decompile java6 web application
  • Passing keycloak configuration parameters in the code rather than reading from application.properties
  • setDataSource() IO exception
  • Unexpected Output while retrieving Data from mongodb and displaying in a csv file?
  • Algorithm for searching a value in two arrays
  • How to avoid casting with generic return values?
  • Java/RegEx - Negation of pattern not working
  • How to split a string to non empty words if it might include a separator like tab on first place
  • Supplier<Sequence<String>> cannot be iterated more than once
  • Why there is only one thread can actually started in @PostConstruct method?
  • Manage CompletionStage inside of Netty handler
  • Url Problem while Developing on Localhost and deploy on Remote Virtual Server
  • How to identify the missing type id in Jackson error?
  • android data binding error: cannot find symbol
  • Spring Boot application with a jar dependency does not run after maven build
  • Spring Data JPA query , filter ? search engine ? JPQL?
  • Why LiveData returns null in ViewModel?
  • what this line of code mean....new URLClassLoader(new URL[0],getClass().getClassLoader());
  • Why do need to use new Random() instead of just Random Randomnum?
  • I want to access zk components from the java file
  • Insertion Sort Double Array with User Input - JAVA
  • Creating 2 dimesional array with user input and find sum of specific columns
  • can not get Advertising ID Provider in android
  • Convert list of Objects to map of properties
  • How to represent an undirected weighted graph in java
  • Return values as array from collection
  • ByteBuddy generic method return cast to concrete type
  • ImageView hides the round corners of the parent
  • Is there a way to find setter method by its getter method or vice versa in a class?
  • Get aggregated list of properties from list of Objects(Java 8)
  • Unable to find a document in Mongodb where exact date match in java
  • UsernamePasswordAuthenticationFilter skips success handler
  • Use Java filter on stream with in a stream filter
  • Default Login not successful in spring boot 2.1.7
  • Adding key value pairs from a file to a Hashmap
  • Rub regex: matching a char except when after by another char
  • Convert Base64 String to String Array
  • Escape Unicode Character 'POPCORN' to HTML Entity
  • An empty JSON field which is a boolean/nullable field in Java model, is getting converted as null
  • Mongo java driver cannot find public constructor for interface
  • How to unit test writing a file to AWS Lambda output stream?
  • How to make a GitHub GraphQL API Call from Java
  • What's the difference between @ComponentScan and @Bean in a context configuration?
  • Expected class or package adding a view using a class
  • can be delete of a element in a static array be O(1)?
  • Instance variable heap or stack ? ( with specific example)
  • Assert progress of ProgressBar in Espresso test
  • How to detect if gson.fromjson() has excess elements
  • I cant generate the proper code to select the a specific filter on a BI dashboard I am working on
  • How to Inject Dependencies into a Servlet Filter with Spring Boot Filter Registration Bean?
  • Thrift types as a Generic
  • Effective algorithm to random 4 unique integers less than a big max such as 100_000
  • Combining or and negation in Java regex?
  • Unable to instantiate default tuplizer Exception
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com