xxxxxxxxxx
Format Pattern Result
-------------- -------
'EEE, MMM d, ''yy' Wed, Jul 10, '96
'h:mm a' 12:08 PM
'yyyyy.MMMMM.dd GGG hh:mm aaa' 01996.July.10 AD 12:08 PM
xxxxxxxxxx
import 'package:intl/intl.dart';
DateTime now = DateTime.now();
String formattedDate = DateFormat('yyyy-MM-dd – kk:mm').format(now);
xxxxxxxxxx
dependencies:
intl: ^0.17.0
import 'package:intl/intl.dart';
// 1900-01-01 00:00:00.000 --- yyyyy-MM-dd hh:mm
DateTime now = clock.now();
String formattedDate = DateFormat('yyyyy-MM-dd hh:mm').format(now);
DateTime dateTime = dateFormat.parse(formattedDate); //Converting String to DateTime object
xxxxxxxxxx
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
}
xxxxxxxxxx
// timestamp string "2012-02-27 11:11:22"
var now = DateTime.parse("2012-02-27 11:11:22");
// define format that you wants
var dateFormatter = DateFormat('dd-MM-yyyy');
var timeFormatter = DateFormat('hh:mm a');
// now we can use above formatters to format
String formattedDate = dateFormatter.format(now);
String formattedTime = timeFormatter.format(now);
print(formattedDate); // o/p=> 2012-02-27
print(formattedTime); // o/p=> 11:11 AM
xxxxxxxxxx
import 'package:intl/intl.dart';
void main() {
final dateTime = DateTime(2022, 11, 15, 13, 45);
final formattedDate = DateFormat.yMMMMEEEEd().format(dateTime);
print(formattedDate);
}
xxxxxxxxxx
import 'package:intl/intl.dart';
void main() {
DateTime now = DateTime.now();
// Format datetime object as a string
String formattedDate = DateFormat('yyyy-MM-dd').format(now);
print('Formatted date: $formattedDate');
}