Timo
Timo

Reputation: 165

Dart/Flutter: Firebase Timestamp to Date behaves different on different devices

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

Upvotes: 0

Views: 576

Answers (2)

Doug Stevenson
Doug Stevenson

Reputation: 317487

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.

Upvotes: 0

Anton Potapov
Anton Potapov

Reputation: 1275

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

Upvotes: 2

Related Questions