DateTime manipulation and formatting are essential skills for any mobile app developer, especially when working with date and time-related data. Flutter, a popular cross-platform framework, provides powerful tools for handling DateTime objects and formatting them to meet your app’s needs. In this blog post, we will explore the various aspects of DateTime formatting in Flutter and learn how to display dates and times in a user-friendly manner.

Installation⚙️

dependencies:
  intl: <latest_version>

Notation🪧

  • y: The year, as a 4-digit integer.
  • M: The month, as a 2-digit integer.
  • d: The day of the month, as a 2-digit integer.
  • H: The hour of the day, in 24-hour format.
  • m: The minute of the hour, as a 2-digit integer.
  • s: The second of the minute, as a 2-digit integer.
  • a: The AM/PM indicator, is a 2-digit integer.

Example💡

Date & Time📆⏰

Sr.PatternResult
1DateFormat(‘EEEE, MMM d, yyyy’).format(DateTime.now())Wednesday, Oct 18, 2023
2DateFormat(‘EE, MMM d, yyyy’).format(DateTime.now())Wed, Oct 18, 2023
3DateFormat(‘EE, MMMM d, yyyy’).format(DateTime.now())Wed, October 18, 2023
4DateFormat(‘EE, MMMM d, yy’).format(DateTime.now())Wed, October 18, 23
5DateFormat(‘MM/dd/yyyy’).format(DateTime.now())10/18/2023
6DateFormat(‘MM-dd-yyyy HH:mm’).format(DateTime.now())10-18-2023 19:48
7DateFormat(‘MMM d, h:mm a’).format(DateTime.now())Oct 18, 7:48 PM
8DateFormat(‘MMMM yyyy’).format(DateTime.now())October 2023
9DateFormat(‘MMM d, yyyy’).format(DateTime.now())Oct 18, 2023
10DateFormat(‘E, d MMM yyyy HH:mm:ss’).format(DateTime.now())Wed, 18 Oct 2023 19:48:45
11DateFormat(‘yyyy-MM-ddTHH:mm:ss’).format(DateTime.now())2023-10-18T19:48:47
12DateFormat(‘dd.MM.yy’).format(DateTime.now())18.10.23
13DateFormat(‘HH:mm:ss.SSS’).format(DateTime.now())19:48:54.318
Date & Time Table Example

Date 📆

Sr.PatternResult
1DateFormat(‘EE’).format(DateTime.now())Wed
2DateFormat(‘EEEE’).format(DateTime.now())Wednesday
3DateFormat(‘d’).format(DateTime.now())18
4DateFormat(‘M’).format(DateTime.now())10
5DateFormat(‘MM’).format(DateTime.now())10
6DateFormat(‘MMM’).format(DateTime.now())Oct
7DateFormat(‘MMMM’).format(DateTime.now())October
8DateFormat(‘yy’).format(DateTime.now())23
9DateFormat(‘yyyy’).format(DateTime.now())2023
10DateFormat(‘EE, d/MM’).format(DateTime.now())Wed, 18/10
11DateFormat(‘EE, MMM yy’).format(DateTime.now())Wed, Oct 23
12DateFormat(‘Q’).format(DateTime.now())4
13DateFormat(‘QQ’).format(DateTime.now())04
14DateFormat(‘QQQ’).format(DateTime.now())Q4
15DateFormat(‘QQQQ’).format(DateTime.now())4th quarter
16DateFormat(‘EE, d/MM/yyyy’).format(DateTime.now())Wed, 18/10/2023
17DateFormat(‘EEEE, d/MM/yyyy’).format(DateTime.now())Wednesday, 18/10/2023
18DateFormat(‘yQQQ’).format(DateTime.now())Q4 2023
19DateFormat(‘yQQQQ’).format(DateTime.now())4th quarter 2023
20DateFormat(‘MM/dd/yyyy’).format(DateTime.now())10/18/2023
21DateFormat(‘MM:dd:yyyy’).format(DateTime.now())10:18:2023
22DateFormat(‘EE MM yyyy’).format(DateTime.now())Wed 10 2023
23DateFormat(‘EEEE MM yyyy’).format(DateTime.now())Wednesday 10 2023
24DateFormat(‘EEEE MMMM yyyy’).format(DateTime.now())Wednesday October 2023
25DateFormat(‘EEEE d MMMM yyyy’).format(DateTime.now())Wednesday 18, October 2023
26DateFormat(‘d MMMM EEEE yyyy’).format(DateTime.now())18 October Wednesday 2023
27DateFormat(‘MMM E d’).format(DateTime.now())Oct Wed 18
Date Example

Time ⏰

Sr.PatternResult
1DateFormat(‘h:mm a’).format(DateTime.now())10:28 PM
2DateFormat(‘HH:mm:ss’).format(DateTime.now())22:28:56
3DateFormat(‘HH:mm:ss.SSS’).format(DateTime.now())22:29:00.057
Time Example

Demo 🚀

YouTube

Website

Conclusion🎯

Intl package is very helpful for formatting Date and Time or any type of pattern.

The above blog and example will help the developer to expand their capabilities with different date and time formatting.

The source code of the full project is given below

GitHub repo with full code here

Write A Comment

Pin It
Top Most Used Animation Widgets You Need to Know in 2024 Top 10+ Free Websites for Hosting for Beginners Developers Flutter AbsorbPointer class Use case in Depth 2023