时间戳到日期时间转换Firebase到Flatter

时间戳到日期时间转换Firebase到Flatter,firebase,flutter,google-cloud-firestore,Firebase,Flutter,Google Cloud Firestore,直截了当地说。我是Firebase Firestore的新手 我有一个模型: @JsonSerializable() class CategoryEntity extends Equatable { final String id; final String name; @JsonKey(fromJson: _fromJson, toJson: _toJson) final DateTime createdDate;

直截了当地说。我是Firebase Firestore的新手

我有一个模型:


     @JsonSerializable()
      class CategoryEntity extends Equatable {
       final String id;
       final String name;
       @JsonKey(fromJson: _fromJson, toJson: _toJson)
       final DateTime createdDate;
       @JsonKey(fromJson: _fromJson, toJson: _toJson)
       final DateTime updatedDate; 
       final String description;

    const CategoryEntity(
      this.id,
      this.name,
      this.createdDate,
      this.updatedDate,
      this.description,
    );
要保存在Firebase Firestore中的数据是
createDate
UpdateDate
的时间戳

但问题是我无法将数据从Firebase转换为本地数据。save方法将
dateCreate
转换为Timestamp fine

     static DateTime _fromJson(int int) =>
        DateTime.fromMillisecondsSinceEpoch(int);
      static int _toJson(DateTime time) => time.millisecondsSinceEpoch;

请提供任何解决方案。

据我所知,您希望在本地时间向用户显示服务器时间戳

我有两种方法你可以检查

一个使用这个软件包,会根据用户的时间显示你的时间

A mini truth table for the format of the value returned by the function:
< 1 second : "Just now"
< 60 seconds : "X seconds" (2-59)
< 2 minutes : "1 minute"
< 60 minutes : "X minutes" (2-59)
< 2 hours : "1 hour"
< 24 hours : "X hours" (2-23)
< 2 days : "1 day"
< 7 days : "X days" (2-6)
< 2 weeks : "1 week"
< 28 days : "X weeks" (2-3)
< 30.44 * 1.5 days : "1 month"
< 365 - 15.22 days : "X months" (2-12)
< 730 days : "1 year"
Rest: "X years"

你可以在这篇文章上看到答案,了解更多信息

谢谢!,但问题在于无法将时间戳转换为日期时间。出现异常。这主要发生在firebase firestore集合中,将数据另存为时间戳。异常错误消息是什么?
import 'package:intl/intl.dart';

int timeInMillis = 1586348737122; //no need to convert it just set the timestamp here.
var date = DateTime.fromMillisecondsSinceEpoch(timeInMillis);
var formattedDate = DateFormat.yMMMd().format(date); //