convert timestamp to DateTime in flutter code example

Example 1: flutter firestore timestamp to datetime

DateTime.parse(timestamp.toDate().toString())

Example 2: how to convert timestamp to datetime in dart

Timestamp time; //from firebase
DateTime.fromMicrosecondsSinceEpoch(time.microsecondsSinceEpoch)

Example 3: flutter date time to timestamp

DateTime currentPhoneDate = DateTime.now(); //DateTime

Timestamp myTimeStamp = Timestamp.fromDate(currentPhoneDate); //To TimeStamp

DateTime myDateTime = myTimeStamp.toDate(); // TimeStamp to DateTime

print("current phone data is: $currentPhoneDate");
print("current phone data is: $myDateTime");

Tags:

Dart Example