Flutter date formatting library date_format
The third-party library date_format can easily format the date and convert it into a string output in the corresponding format.
Add dependency library
- First, find the pubspec.yaml file in the application package directory, and add the following dependencies:
dependencies:
date_format: ^1.0.9
- Update dependencies
Click "Pub get" directly in Android Studio or use the following command:
flutter pub get
- Import library
import 'package:date_format/date_format.dart';
Then you can use date_format.
Usage example
- Example 1:
print(formatDate(DateTime(2020, 12, 23), [yyyy, '-', mm, '-', dd]));
Output: 2020-12-23
- Example 2:
print(formatDate(DateTime(2020, 2, 21), [yy, '-', M, '-', d]));
Output: 20-feb-21
- Example 3:
print(formatDate(
DateTime(2020, 12, 23, 15, 40, 10), [HH, ':', nn, ':', ss]));
Output: 15:40:10
- Example 4:
print(formatDate(
DateTime(2020, 12, 23, 15, 40, 10), [HH, ':', nn, ':', ss, z]));
Output: 15:40:10+0100
date_format official website address
https://pub.dev/packages/date_format
**PS: For more exciting content, please check --> "Flutter Development"
**PS: For more exciting content, please check --> "Flutter Development"
**PS: For more exciting content, please check --> "Flutter Development"