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

Time:02-04

'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".

CodePudding user response:

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.

CodePudding user response:

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

This is How you can parse .

thanks

CodePudding user response:

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));
  •  Tags:  
  • Related