简体   繁体   English

Dart/Flutter:Firebase Timestamp to Date 在不同设备上的表现不同

[英]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.我有一个 Flutter 应用程序,我在我的 Firebase 中存储带有活动日期的活动。

Firebase 中的活动日期

When showing those activities in my app I noticed that the Date gets converted differently from different devices.在我的应用程序中显示这些活动时,我注意到日期在不同设备上的转换方式不同。

我使用 toDate() 来转换时间戳

The output in my Virtual Device when debugging is in the end the 29.07.2018 instead of the 30.07.2018.调试时我的虚拟设备中的输出最终是 29.07.2018 而不是 30.07.2018。 How can I fix this?我怎样才能解决这个问题?

转换后从流打印日期

在此处输入图片说明

This may happen because of locale.这可能是由于语言环境而发生的。 Try to use DateFormat from https://pub.dev/packages/intl尝试使用https://pub.dev/packages/intl 中的DateFormat

Firestore Timestamps are always stored in UTC, like pretty much all other date types in any modern operating system. Firestore 时间戳始终以 UTC 格式存储,就像任何现代操作系统中的所有其他日期类型一样。 What you see in the Firebase console is the date formatted for the locale configured on the local machine that's viewing the console.您在 Firebase 控制台中看到的是针对查看控制台的本地计算机上配置的区域设置的日期格式。

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.如果你想在你的应用中格式化时间戳,你应该考虑使用 Flutter 或你正在使用的任何平台提供的日期格式化实用程序。 Usually users expect to see timestamp formatted for their own chosen locale.通常用户希望看到针对他们自己选择的语言环境格式化的时间戳。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM