Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Insert commas into string flutter

Say I have a string value as: June 22 2022 and I want to add comma with code such that it prints out this value: June 22, 2022. How do I achieve that?

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

In this particular case, you could use DateTime‘s DateFormatter:

import 'package:intl/intl.dart';

void main() {
  DateFormat inputFormatter = DateFormat('MMMM dd yyyy');
  DateFormat outputFormatter = DateFormat('MMMM dd, yyyy');
  DateTime date = inputFormatter.parse('February 13 2042');
  String formatted = outputFormatter.format(date);
  print(formatted);
}

Console log

February 13, 2042
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading