Search code examples
datedartflutterepoch

Flutter/Dart: DateTime.fromMillisecondsSinceEpoch return the incorrect time


DateTime.fromMillisecondsSinceEpoch() method will return the DateTime since 1970-1-1 0:0:0.0 + milliseconds

Actually, if we pass 1 milliseconds, it will return 1970-1-1 8:0:0.1, this confused me.


Solution

  • Try passing isUtc: true. If you don't, the DateTime will be based on your local time zone. From the DateTime.fromMillisecondsSinceEpoch documentation:

    If isUtc is false then the date is in the local time zone.