0

Hello friend I am new in dart fetching data from Api now I want format this date time. In this way => Mar 20, 2021 11:36 am.. While json response coming this way =>":"2021-03-20 11:36:00

Here is my json full response file please check answer the question?

"message":"Data fetched successfully",
   "data":[
      {
         "id":1,
         "public_id":"ed0042ca-5a14-476b-9b65-66461efa81ae",
         "title":"LIVE CONCERT",
         "image":"https:\/\/livinghopemobile.com\/public\/storage\/event\/200321_113705_image.png",
         "datetime":"2021-03-20 11:36:00",  <=
         "description":"LIVE CONCERT",
         "created_at":"2021-03-20T06:37:05.000000Z",
         "updated_at":"2021-03-29T07:18:50.000000Z"
      }
   ]
}
mark anthony
  • 227
  • 1
  • 3
  • 14

3 Answers3

1
 String date = DateFormat("MMM dd, yyyy hh:mm a").format(DateTime.parse("2021-03-20 11:36:00"));
 print(date); // =>Mar 20, 2021 11:36 AM
Huthaifa Muayyad
  • 11,321
  • 3
  • 17
  • 49
0

try out this

 var date = "2021-03-24T08:57:47.812" 
 var dateTime =  DateTime.parse("$date");
 var stdTime =  DateFormat('MMM d, yy hh:mm a').format(dateTime).toString();
Jahidul Islam
  • 11,435
  • 3
  • 17
  • 38
0

Try this

var time = DateTime.parse(data[0]['datetime']);

And then you can look up here on the dates format list Here

var myTime =  DateFormat('MMM d, yy hh:mm a').format(time);
Ibrahim Ali
  • 2,083
  • 2
  • 15
  • 36