import 'package:intl/intl.dart';
DateTime now = DateTime.now();
String formattedDate = DateFormat('yyyy-MM-dd – kk:mm').format(now);
Add this Package or click on the sourse
https://pub.dev/packages/intl
import 'package:intl/intl.dart';
var year = DateFormat('yyyy').format(DateTime.now());
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
import 'package:intl/intl.dart';
dart pub add intl
DateTime dateTime = dateFormat.parse("2019-07-19 8:40:23");
For IIS-Hosting with MyLittelAdmin Flutter Developer ( Hosting with SQLServer myLittleAdmin conflict date)
Use this Format
// Define a simple format function from scratch
String simplyFormat({required DateTime time, bool dateOnly = false}) {
String year = time.year.toString();
// Add "0" on the left if month is from 1 to 9
String month = time.month.toString().padLeft(2, '0');
// Add "0" on the left if day is from 1 to 9
String day = time.day.toString().padLeft(2, '0');
// Add "0" on the left if hour is from 1 to 9
String hour = time.hour.toString().padLeft(2, '0');
// Add "0" on the left if minute is from 1 to 9
String minute = time.minute.toString().padLeft(2, '0');
// Add "0" on the left if second is from 1 to 9
String second = time.second.toString();
// If you only want year, month, and date
if (dateOnly == false) {
return "$year-$month-$day $hour:$minute:$second";
}
// return the "yyyy-MM-dd HH:mm:ss" format
return "$year-$month-$day";
}
// simplyFormat(DateTime.now());
DateFormat dateFormat = DateFormat("dd/MM/yyyy HH:mm:ss");