How to format DateTime in Flutter
You can use DateFormat
from intl package.
import 'package:intl/intl.dart';
DateTime now = DateTime.now();
String formattedDate = DateFormat('yyyy-MM-dd – kk:mm').format(now);
How do I format a date with Dart?
You can use the intl
package (installer) to format dates.
For en_US
formats, it's quite simple:
import 'package:intl/intl.dart';
main() {
final DateTime now = DateTime.now();
final DateFormat formatter = DateFormat('yyyy-MM-dd');
final String formatted = formatter.format(now);
print(formatted); // something like 2013-04-20
}
There are many options for formatting. From the docs:
ICU Name Skeleton
-------- --------
DAY d
ABBR_WEEKDAY E
WEEKDAY EEEE
ABBR_STANDALONE_MONTH LLL
STANDALONE_MONTH LLLL
NUM_MONTH M
NUM_MONTH_DAY Md
NUM_MONTH_WEEKDAY_DAY MEd
ABBR_MONTH MMM
ABBR_MONTH_DAY MMMd
ABBR_MONTH_WEEKDAY_DAY MMMEd
MONTH MMMM
MONTH_DAY MMMMd
MONTH_WEEKDAY_DAY MMMMEEEEd
ABBR_QUARTER QQQ
QUARTER QQQQ
YEAR y
YEAR_NUM_MONTH yM
YEAR_NUM_MONTH_DAY yMd
YEAR_NUM_MONTH_WEEKDAY_DAY yMEd
YEAR_ABBR_MONTH yMMM
YEAR_ABBR_MONTH_DAY yMMMd
YEAR_ABBR_MONTH_WEEKDAY_DAY yMMMEd
YEAR_MONTH yMMMM
YEAR_MONTH_DAY yMMMMd
YEAR_MONTH_WEEKDAY_DAY yMMMMEEEEd
YEAR_ABBR_QUARTER yQQQ
YEAR_QUARTER yQQQQ
HOUR24 H
HOUR24_MINUTE Hm
HOUR24_MINUTE_SECOND Hms
HOUR j
HOUR_MINUTE jm
HOUR_MINUTE_SECOND jms
HOUR_MINUTE_GENERIC_TZ jmv
HOUR_MINUTE_TZ jmz
HOUR_GENERIC_TZ jv
HOUR_TZ jz
MINUTE m
MINUTE_SECOND ms
SECOND s
For non-en_US
dates, you need to explicitly load in the locale. See the DateFormat
docs for more info. The date_symbol_data_local.dart
contains all of the formats for each country/language, if you would like a more in-depth look.
Date Time format in Flutter dd/MM/YYYY hh:mm
If you use the intl package
final f = new DateFormat('yyyy-MM-dd hh:mm');
Text(f.format(new DateTime.fromMillisecondsSinceEpoch(values[index]["start_time"]*1000)));
How to format DateTime in Flutter? Remove milliseconds in DateTime?
Try out Jiffy, make it easier to work with date and time
To format your DateTime just pass in your result date
, see below
this.date1 = Jiffy(date).format('yyyy-MM-dd'); // 2021-03-24
// or you can also use default formats
this.date1 = Jiffy(date).yMMMMd; // March 24, 2021
How can I get day name from string date '22 May 2022' in flutter
Try this :
final dateName = DateFormat('EEEE').format(DateFormat("DD MMMM yyyy").parse('22 May 2022'));
Related Topics
How to Automatically Restart a Service Even If User Force Close It
What Is the Meaning of Addtobackstack with Null Parameter
How to Set the Initial Zoom/Width for a Webview
Android L's Ripple Effect - Touch Feedback for Buttons - Using Xml
Camera Preview Image Data Processing with Android L and Camera2 API
How to Set a Viewpager Inside a Fragment
Listen Outgoing Sms or Sent Box in Android
Change the Font of Tab Text in Android Design Support Tablayout
Android Studio:Unmappable Character for Encoding Utf-8
Retrieve Google Access Token After Authenticated Using Firebase Authentication
Remove Application Icon and Title from Honeycomb Action Bar
How to Draw Arc Between Two Points on the Canvas
Does the Android Art Runtime Have the Same Method Limit Limitations as Dalvik
Android Studio/Emulator on MACos with Arm CPU M1
Detect Viewpager Tab Change Inside Fragment
Choosing Photo Using New Google Photos App Is Broken
Android: How to Get a Custom View's Height and Width
How to Get App's Permission for Each App? How to Do It Programmatically on Android