0

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)

Harith AL Any
  • 243
  • 3
  • 16
  • 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 Answers3

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
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