xxxxxxxxxx
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());
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
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';
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');
}
xxxxxxxxxx
//add, intl Flutter package
DateTime datetime = DateTime.now();
print(datetime.toString());
//output: 2021-10-17 20:04:17.118089
String datetime1 = DateFormat("yyyy-MM-dd").format(datetime);
print(datetime1);
//output: 2021-10-17
String datetime2 = DateFormat.Hms().format(datetime);
print(datetime2);
//output (Time): 20:04:17
String datetime3 = DateFormat.MMMMEEEEd().format(datetime);
print(datetime3);
//output: Sunday, October 17