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';
DateTime now = DateTime.now();
String formattedDate = DateFormat('yyyy-MM-dd – kk:mm').format(now);
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
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() {
DateTime now = DateTime.now();
// Format datetime object as a string
String formattedDate = DateFormat('yyyy-MM-dd').format(now);
print('Formatted date: $formattedDate');
}
xxxxxxxxxx
For 'intl' package, use Custom formatting, like:
final dateFormat = DateFormat('hh:mm, MMMM d, y', 'bn');
String formattedDateInBangla = dateFormat.format(DateTime.now);
O/p:
১০:৩৩, ফেব্রুয়ারী ২, ২০২৩
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());