Reputation: 65
Good day i want to format my date 2020-11-05 to 11-05-2020 my database type is timestamp
[![Here is my view ][1]][1] [1]: https://i.sstatic.net/sOgYN.jpg
//this is my my litsview
@override
Widget build(BuildContext context) {
return Scaffold(
body: RefreshIndicator(
onRefresh: getData,
key: _refresh,
child: loading
? Center(child: CircularProgressIndicator())
: ListView.builder(
itemCount: list.length,
itemBuilder: (context, i) {
final x = list[i];
debugPrint(x.toString());
return ExpansionTile(
title: ListTile(
title: Text(
'Transaction ID:\t' +
x.transaction_id +
'\nVesselname:\t' +
x.vesselname +
'\nVoyage #:\t' +
x.voyageno,
style: TextStyle(
fontSize: 15.0, fontWeight: FontWeight.bold))),
children: <Widget>[
ListTile(
title: Text('Ship Call #:\t' + x.scn,
style: TextStyle(fontSize: 15.0))),
//here is my value anchorage estimated time of arrival i want to format it into 11-20-2020
ListTile(
title: Text(
'Anchor Estima Time of Arrival :\n' + x.anchor_eta,
style: TextStyle(fontSize: 15.0))),
ListTile(
title: Text(
'Anchor Actual Time of Arrival :\n' + x.anchor_ata,
style: TextStyle(fontSize: 15.0))),
],
);
},
),
));
} }
Upvotes: 1
Views: 2421
Reputation: 1865
You can use this function for formatting your date
String formatDate(String dbDate){
List<String> dateTimeList = dbDate.split(" ");
List<String> dateList = dateTimeList.first.split("-");
String dateTime = dateList[1]+"-"+dateList.last+"-"+dateList.first + " "+ dateTimeList.last;
return dateTime;
}
Upvotes: 3
Reputation: 494
Hi flutter run(cool name btw),
There are two ways you can do achieve this:
String correctlyFormattedDateTime(DateTime date){
return DateFormat('dd-MM-yyyy').format(date); //=> 02/07/2020
}
String correctlyFormattedDateTime(DateTime date){
return '${date.day}/${date.month}/${date.year}'; //=> 02/07/2020
}
Here is a duplicate of this question
Please leave a comment if you need any further help!
Upvotes: 0