LoginSignup
1
1

More than 3 years have passed since last update.

Flutter×Firebase Timestampの日時情報を表示

Posted at

Flutter×Firebase Timestampの時間表示

流れとしては、
①Firestoreのtimestampで時間取得
②そのtimestampをdatetimeに変更
③テキストとして表示

①以下のコードでtimestampというフィールド名で時間取得

Firestore.instance.collection('コレクション名').add({'timestamp': FieldValue.serverTimestamp()});

スクリーンショット 2020-08-08 15.08.52.png

②datetimeに変更

final timeStamp = snapshot.data.documents[index]['timestamp'];
final d = timeStamp.toDate();

③テキストとして表示


Text(d.year.toString() + '/' + d.month.toString() + '/' + d.day.toString() + ':' + d.hour.toString() + ':' + d.minute.toString + ':' + d.second.toString())

スクリーンショット 2020-08-08 15.10.40.png

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1