Tried to convert firestore
timestamp to string and I got this!
I tried String date = FieldValue.serverTimestamp().toString();
and instead of time stamp I got this as shown in Screenshot1
Tried to convert firestore
timestamp to string and I got this!
I tried String date = FieldValue.serverTimestamp().toString();
and instead of time stamp I got this as shown in Screenshot1
The date inside a Firestore database must be stored as a Date
object as explained here. Assuming that you have public getter named getDate()
inside your model class, to print the date, please use the following code:
Date date = yourModelClass.getDate();
if (date != null) {
DateFormat dateFormat = SimpleDateFormat.getDateInstance(DateFormat.MEDIUM, Locale.US);
String creationDate = dateFormat.format(date);
Log.d("TAG", creationDate);
}
What you are actually printing there is the address of the FieldValue
class from the memory.
okay so the toString() will not output the date formatted since the object returned by the statement FieldValue.serverTimestamp()
is a Date
object so you can do something like this to handle date formatting.
Date now = FieldValue.serverTimestamp();
SimpleDateFormat dateFormatter = new SimpleDateFormat("E, y-M-d 'at' h:m:s a z");
Log.i("Format 1: ", dateFormatter.format(now));