Flutter | How to trim data that is coming from API which is displaying at UI in the form of String

'This is the json which I am getting'

{
"data": {
    "attributes": {
        "serverDate": "2022-02-03T07:07:50.231Z",
        "totalBills": [
            {                                   
                "dueDate": "Tue Jan 04 2022 19:24:15 GMT+0530 (India Standard Time)"
               }
             ]
           }
          }
         }

this is my code which in UI part Text( order.data.attributes.totalBills[0].dueDate),

I want to show output like this in UI "Jan 04 2022".

Upvotes: 1

Views: 432

Answers (3)

Alex Chengalan
Alex Chengalan

Reputation: 8281

By using intl package you can format the date string. For example,

import 'package:intl/intl.dart';
DateFormat.yMMMMEEEEd().format(DateTime.parse(order.data.attributes.totalBills[0].dueDate));

Upvotes: 0

Tasnuva Tavasum oshin
Tasnuva Tavasum oshin

Reputation: 4750

   DateFormat('MMM dd y HH:mm')
   .format(DateTime.parse(
   order.data.attributes.totalBills[0].toString()))
  .toString()

This is How you can parse .

thanks

Upvotes: 0

Amarjeet Patidar
Amarjeet Patidar

Reputation: 666

Just add:

Text( order.data.attributes.totalBills[0].dueDate.substring(3,16));

3 and 16 are the range of index(int) of starting and ending position.

Upvotes: 3

Related Questions