-3

I want to show a date time in the following format 01-Mar-2000 10:10:10 PM/AM.

How to achieve it?

Please suggest a one line answer to write optimized code.

1 Answers1

1

You can use intl package DateFormat.

The format will be DateFormat("dd-MM-yyyy h:mm:ss a");

single line will be

DateFormat("dd-MM-yyyy h:mm:ss a").format(dateTime);
final dateTime = DateTime.now();
DateFormat formater = DateFormat("dd-MM-yyyy h:mm:ss a");
final data = formater.format(dateTime);
print(data);//30-10-2022 4:14:19 PM
Md. Yeasin Sheikh
  • 54,221
  • 7
  • 29
  • 56