am using Date formatter in my app to display some dates.. but i want this date to be shown in Arabic .. so i tried to change locale of the formatter like this this:
var now = new DateTime.now();
var formatter = DateFormat.yMMMd("ar_SA");
String formatted = formatter.format(now);
print(formatted);
but its not working ..
if i changed it to this:
var now = new DateTime.now();
var formatter = DateFormat.yMMMd("en_US");
String formatted = formatter.format(now);
print(formatted);
Will work fine .. but i want the date to be displayed in Arabic ..
how to achieve this? i want the date to be for example ١١ يناير ٢٠١٨.. how to do it?
You need to use initializeDateFormatting
to get the correct date formatter like this:
initializeDateFormatting("ar_SA", null).then((_) {
var now = DateTime.now();
var formatter = DateFormat.yMMMd('ar_SA');
print(formatter.locale);
String formatted = formatter.format(now);
print(formatted);
});
or with async-await you could do:
await initializeDateFormatting("ar_SA", null);
var now = DateTime.now();
var formatter = DateFormat.yMMMd('ar_SA');
print(formatter.locale);
String formatted = formatter.format(now);
print(formatted);
This results in the following output for me:
ar
١٢ نوفمبر ٢٠١٨
and just make sure import data local
import 'package:intl/date_symbol_data_local.dart';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With