Home > Blockchain >  Dart datetime parse why I'm getting wrong value?
Dart datetime parse why I'm getting wrong value?

Time:07-06

I'm trying to parse a DateTime from a response of a JSON object

print(DateTime.parse("2022-07-05T15:11:44 09:00"));

Getting output:

2022-07-05 06:11:44.000Z

Desired output:

2022-07-05 03:11:44.000Z

How I will get the desired output?

CodePudding user response:

Try calling .toLocal():

void main() {
    print(DateTime.parse('2022-07-05 06:11:44.000Z').toLocal());
}

CodePudding user response:

You parse local time, Dart return UTC time

  •  Tags:  
  • dart
  • Related