How To Show Firestore Servertimestamp Correctly Depending On Local
I cant get this right and wonder how to show the Firestore FieldValue.serverTimestamp() formatet individual depending on what local the device has. The Firestore timestamp look li
Solution 1:
What I normally do is simply use Date and setTimezine. The timestamp variable in my models are long variables and I use a code like this to convert the server time into a local one.
DateFormatformatter= DateFormat.getDateInstance(DateFormat.SHORT, Locale.getDefault());
formatter.setTimeZone(TimeZone.getTimeZone("STRING FOR TIMEZONE"));
StringlocalizedToday= formatter.format(YOURDATEOBJECT);
Solution 2:
Assuming that you have a model class named MyClass
that has a Date
field and public setters and getters, to get the date, please use the following code:
Datedate= yourClass.getDate();
if (date != null) {
DateFormatdateFormat= SimpleDateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL, Locale.getDefault());
StringcreationDate= dateFormat.format(date);
Log.d("TAG", creationDate);
}
Post a Comment for "How To Show Firestore Servertimestamp Correctly Depending On Local"