How to Format DateTime In Flutter ?

· 3 min read
How to Format DateTime In Flutter
How to Format DateTime In Flutter

Many times it may happen that the user needs to display the current  DateTime in a Text Widget. Depending on the user requirement user needs to display Date Time as per the Client Requirement. So in this article, We will discuss How to Format DateTime In Flutter?

How to Format DateTime In Flutter?

Depending on a client’s requirement we need to format DateTime. Users can take a look at intl package.

This package provides internationalization and localization facilities, including message translation, plurals and genders, date/number formatting and parsing, and bidirectional text.

To use the above package we need to import it like the below:

import 'package:intl/intl.dart';

Now we need to current DateTime using the below code Snippet.

DateTime now =;
String formattedDate = DateFormat('yyyy-MM-dd – kk:mm').format(now);

Converting DateTime object to String

String string = dateFormat.format(;

Converting String to DateTime object

DateTime dateTime = dateFormat.parse("2019-07-19 8:40:23");

User can also create a custom function like the below:

todayDate() {
    var now = new;
    var formatter = new DateFormat('dd-MM-yyyy');
    String formattedTime = DateFormat('kk:mm:a').format(now);
    String formattedDate = formatter.format(now);



You can also use this syntax. For YYYY-MM-JJ HH-MM:

var now =;
var month = now.month.toString().padLeft(2, '0');
var day =, '0');
var text = '${now.year}-$month-$day ${now.hour}:${now.minute}';
Use the String split method to remove :00.000
var formatedTime = currentTime.toString().split(':')
Code for YYYY-MM-DD HH:MM: SS format without using a library
var stringList = RegExp(r"[T\.]"));
var formatedDate = "${stringList[0]} ${stringList[1]}";


In this article, We have been through How to Format DateTime In Flutter?

Keep Learning!!! Keep Fluttering !!!

Still, need a Support for Flutter Development? Do let us know. is our portal Platform dedicated to Flutter Technology and Flutter Developers. The portal is full of cool resources from Flutter like Flutter Widget GuideFlutter ProjectsCode libs and etc. is one of the most popular online portal dedicated to Flutter Technology and daily thousands of unique visitors come to this portal to enhance their knowledge on Flutter.

Leave a Reply