leon
leon

Reputation: 560

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.

Upvotes: 0

Views: 4470

Answers (1)

jamesdlin
jamesdlin

Reputation: 90055

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.

Upvotes: 2

Related Questions