Home > database >  DateTime.parse giving Wrong Date
DateTime.parse giving Wrong Date

Time:02-08

I am fetching date from Firestore in string format then i am casting in DateTime but DateTime.parse() giving me wrong date

The actual date is (yyyy-MM-dd HH:mm) = 2022-01-29 15:23 The output is (yyyy-MM-dd HH:mm) = 2024-05-01 15:23

Can you explain why it is giving

CodePudding user response:

Parse it using DateFormat.parse(), like this:

dependencies:
  intl: ^0.17.0

then:

import 'package:intl/intl.dart';

DateFormat dateFormat = DateFormat("yyyy-MM-dd HH:mm:ss");

DateTime dateTime = dateFormat.parse("2019-07-19 8:40:23"); // <-- your string inside 
  •  Tags:  
  • Related