How to use localized date in Flutter? 

To use localized date in Flutter, you can utilize the DateFormat class from the intl package. This class allows you to format dates according to the user's locale, making it easy to display dates in a localized format that the user is familiar with. Here is an example of how to use the DateFormat class in Flutter:

DateTime now = DateTime.now();

String formattedDateEn = DateFormat.yMd('en').format(now);
print(formattedDateEn); // 3/28/2023

String formattedDateFr = DateFormat.yMd('fr').format(now);
print(formattedDateFr); // 28/03/2023

You can also format dates in your localization messages using either the gen_l10n or Flutter Intl approaches and generated localization code will handle that for you. Here is an example of such a message in ARB file:

"pageHomeSampleCurrentDate": "Date: {date}",
"@pageHomeSampleCurrentDate": {
  "placeholders": {
    "date": {
      "type": "DateTime",
      "format": "yMd"
    }
  }
}

Flutter internationalization tutorial:

Copyrights 2024 © Localizely