【发布时间】:2017-01-31 16:33:43
【问题描述】:
我在 firebase json 中将 DateTime 存储为 millisecondsSinceEpoch,然后在调用 fromMap 时我想从 millisecondsSinceEpoch 进行转换。
除了我目前的方法之外,哪种方法最合适?
new DateTime.fromMillisecondsSinceEpoch(map['created_at'])
消息类
class Message {
final String name;
final String text;
String photoURL;
String imageURL;
DateTime created_at;
Message(this.name, this.created_at, [this.text, String photoURL, this.imageURL]) {
this.photoURL = photoURL ??
"https://lh3.googleusercontent.com/"
}
Message.fromMap(Map map) :
this(map['name'], new DateTime.fromMillisecondsSinceEpoch(map['created_at']), map['text'], map['photoURL'], map['imageURL']);
Map toMap() =>
{
"name": name,
"created_at": created_at.millisecondsSinceEpoch,
"text": text,
"photoURL": photoURL,
"imageURL": imageURL
};
}
【问题讨论】:
-
你现在的使用方式有什么问题?
标签: json datetime angular firebase dart