'Date Time format in Flutter like Today / dd/MM/YYYY hh:mm

I want to add DateFormat in flutter like

Today / dd/MM/YYYY hh:mm

How can I do this and compare it to List items depend on the date

//  This is the item I want to list depends on the date 
ListView.builder(
    itemCount: data.expenseList.length,
    itemBuilder: (context, index) {
        return TransactionIncome(
            index: index,
            expense: data.expenseList[index],
        );
    },
)


Solution 1:[1]

First you need to add intl package to your pubspec.yaml

Then import it

import 'package:intl/intl.dart';

Then use this method to parse your date "yourDateValue"

final DateFormat formatter = DateFormat("Today / dd/MM/YYYY hh:mm");
final String formatted = formatter.format(yourDateValue);

Solution 2:[2]

You can get the formated date and time as you mentioned by following the method

add these to pubspec.yaml file

  intl: ^0.17.0
  date_format: ^2.0.5

and implement it like;

DateTime nowTime = DateTime.now();
 var nowFormatedDate = DateFormat.yMd().format(nowTime).toString();
var nowFormatedTme = formatDate(
    DateTime(2019, 08, 1, nowTime.hour, nowTime.minute),
    [hh, ':', nn, " ", am]).toString();
var formatedDateTime = nowFormatedDate + ' / ' + nowFormatedTme;
print(formatedDateTime);

Note: User your own time instead of nowTime

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 TebessaDev
Solution 2 navidanchitrali