Search code examples
flutterdatetimedartdatetime-format

Flutter how to convert timestamp date time


I am getting date and time from store. In data base its look like this

enter image description here

Need to know how can I show this as DD/MM/YY

I am trying to do like this

    String timeString = snapshot.data[index]['lastupdate'].toString();
    DateTime date = DateTime.parse(timeString);
    print(DateFormat('yyyy-MM-dd').format(date));

Its showing error of Invalid date format


Solution

  • Try like this your lastupdate date is not convertime inDate thats why its showing error

    DateTime date = DateTime.parse(snapshot.data[index]['lastupdate'].toDate().toString());
    print(DateFormat('dd-MMM-yyy').format(date));