I have a flutter app where I am storing activities with an activity date in my firebase.

Activity date in firebase

When showing those activities in my app I noticed that the Date gets converted differently from different devices.

I use toDate() to convert the timestamp

The output in my Virtual Device when debugging is in the end the 29.07.2018 instead of the 30.07.2018. How can I fix this?

print date from stream after conversion

enter image description here


Solution 1: Anton Potapov

This may happen because of locale. Try to use DateFormat from https://pub.dev/packages/intl


Solution 2: Doug Stevenson

Firestore Timestamps are always stored in UTC, like pretty much all other date types in any modern operating system. What you see in the Firebase console is the date formatted for the locale configured on the local machine that's viewing the console.

If you want to format a timestamp in your app, you should look into using the date formatting utilities provided by Flutter or whatever platform you're using. Usually users expect to see timestamp formatted for their own chosen locale.