flutter date time code example
Example 1: flutter get current date
import 'package:intl/intl.dart';
main() {
static final DateTime now = DateTime.now();
static final DateFormat formatter = DateFormat('yyyy-MM-dd');
final String formatted = formatter.format(now);
print(formatted); // something like 2013-04-20
}
// https://pub.dev/documentation/intl/latest/intl/DateFormat-class.html
Example 2: flutter datetime format
import 'package:intl/intl.dart';
DateTime now = DateTime.now();
String formattedDate = DateFormat('yyyy-MM-dd – kk:mm').format(now);
Example 3: how to display current date time in flutter
DateTime dateToday = DateTime(DateTime.now().year, DateTime.now().month, DateTime.now().day) ;
Example 4: flutter date time
var now = new DateTime.now();
var moonLanding = DateTime.parse(now);
moonLanding.year;
moonLanding.hour;
moonLanding.month;
moonLanding.year.toString() + '-' + moonLanding.month.toString() + '-' + moonLanding.day.toString()
############################ OR ###########################
import 'package:intl/intl.dart';
var dt = DateTime.now();
var newFormat = DateFormat("yy-MM-dd");
String updatedDt = newFormat.format(dt);
print(updatedDt); // 20-04-03
var newDt = DateFormat.yMMMEd().format(dt);
print(newDt); // Fri, Apr 3, 2020
reference :
https://medium.com/flutter-community/working-with-dates-in-dart-e81c70911811