Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get localized short date pattern as String?

I'd like to get the pattern of a "short date" as a String that is customized to the user's locale (e.g. "E dd MMM"). I can easily get a localized DateFormat-object using
DateFormat mDateFormat = android.text.format.DateFormat.getDateFormat(mContext);
but DateFormat doesn't have a .toPattern()-method.

If I use

SimpleDateFormat sdf = new SimpleDateFormat();
String mDateFormatString = sdf.toPattern();

I don't know how to only get the short date pattern String instead of the full M/d/yy h:mm a

like image 932
Nick Avatar asked Jun 28 '26 19:06

Nick


1 Answers

I ended up using

String deviceDateFormat = DateFormat.getBestDateTimePattern(Locale.getDefault(), "E dd MMM");

will will give me the "best regional representation" of the supplied input-format, in this case the weekday, day, and month.

like image 87
Nick Avatar answered Jul 01 '26 09:07

Nick



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!