Home > Net >  Date Time format in Flutter like Today / dd/MM/YYYY hh:mm
Date Time format in Flutter like Today / dd/MM/YYYY hh:mm

Time:03-17

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],
                                
                              );
                            },
                          )`

CodePudding user response:

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

CodePudding user response:

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

  • Related