Ferenc Orosi
Ferenc Orosi

Reputation: 265

Flutter: DateTime fromMillisecondsSinceEpoch shows one day less

I get a time value from an API which is a unix value, but when i use DateTime.fromMillisecondsSinceEpoch, it shows one day less. I don't understand why. Please explain me what i'm doing wrong.

I think timezones made the problem, but i don't know how to fix it.

Unix value from API

1623283201 // 2021-06-10 0:00:01.000

This is my code

var date = DateTime.fromMillisecondsSinceEpoch((json['time_last_update_unix']) * 1000);
print("This is the date " + date.toString()); // 2021-06-09 20:00:01.000

Upvotes: 0

Views: 608

Answers (1)

RusJaI
RusJaI

Reputation: 794

If your date input carrying a time zone which is not your local timezone, you have to explicitly change the following bool value

bool isUtc = true

Default value is false and date is identified from your local timezone. For more detail please refer this link https://api.flutter.dev/flutter/dart-core/DateTime/DateTime.fromMillisecondsSinceEpoch.html

Upvotes: 1

Related Questions