I work on flutter api wordpress project . How format date from wordpress api . date came in this format (2019-08-26T16:23:06) . i want to remove second and year . and month like (June , April)
Asked
Active
Viewed 1,110 times
0
-
Possible duplicate of [convert datetime string to datetime object in dart?](https://stackoverflow.com/questions/49385303/convert-datetime-string-to-datetime-object-in-dart) – easeccy Aug 28 '19 at 15:03
3 Answers
1
you can use https://pub.dev/packages/intl and DateFormat :
DateTime dateTime = DateTime.parse(data[index]['date']);
String dateformat = DateFormat( "dd.MM.yyyy HH:mm").format(dateTime);

Philzilla
- 11
- 2
0
You can create a DateFormat object that fit your needs and use it to format your date.
Head over to the documentation to examples: https://api.flutter.dev/flutter/intl/DateFormat-class.html

Rodrigo Bastos
- 2,230
- 17
- 17
-
Since the string is already formatted in ISO9601 format, `DateTime.parse()` is all that's needed. – Richard Heap Aug 28 '19 at 16:20
-
https://stackoverflow.com/questions/49385303/convert-datetime-string-to-datetime-object-in-dart – Harith AL Any Aug 28 '19 at 22:14
0
I solve my problem with this function
timenow() {
var day = DateTime.parse(
snapshot.data[index].date)
.day;
var month = DateTime.parse(
snapshot.data[index].date)
.month;
var year = DateTime.parse(
snapshot.data[index].date)
.year;
var hour = DateTime.parse(
snapshot.data[index].date)
.hour;
var min = DateTime.parse(
snapshot.data[index].date)
.minute;
return year.toString() +
"/" +
month.toString() +
"/" +
day.toString() +
" " +
hour.toString() +
":" +
min.toString();
} // format date and time

Harith AL Any
- 243
- 3
- 16