Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 211 Vote(s) - 3.44 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Flutter app error - type 'Timestamp' is not a subtype of type 'DateTime'

#21
There are various ways to convert `TimeStamp to DateTime` which differs based on the scenario.
I have tried to gather all the possible ways to convert `Firebase timeStamp` to `DateTime`. Pick which works for you.

---

#### Conversion of `Firebase timestamp` to `DateTime`:

1. document['timeStamp'].toDate()
2. (document["timeStamp"] as Timestamp).toDate()

3. DateTime.fromMillisecondsSinceEpoch(document['timeStamp'].millisecondsSinceEpoch);

5. Timestamp.fromMillisecondsSinceEpoch(document['timeStamp'].millisecondsSinceEpoch).toDate();


5. If `timeStamp` is in `microseconds` use:

DateTime.fromMicrosecondsSinceEpoch(timestamp * 1000000);
6. If `timeStamp` is in `milliseconds` use:

DateTime.fromMillisecondsSinceEpoch(timestamp * 1000);
7. Add the following function in your dart file.

String formatTimestamp(Timestamp timestamp) {
var format = new DateFormat('yyyy-MM-dd'); // <- use skeleton here
return format.format(timestamp.toDate());
}
call it as `formatTimestamp(document['timestamp'])`
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through