I am trying to format
DateTime result and display it to the user in user's current device locale.
Currently I can either display entire
DateTime such as following:
Or by specifying exact format like this:
which results in following:
My problem with this solution is, while this format might be acceptable in EU; in e.g. US (and many other countries) they are used to a different Date format, e.g.
My question is: how to return only Date (not time) to user in their current locale's format?
One needs to retrieve current locale and pass it to the format function. I am using custom localizations class, yet with out of the box solution it would look like this:
Solution 1: Günter Zöchbauer
You can pass a locale to
format = DateFormat.yMMMd("en_US");
Solution 2: Miguel Beltran
I know this is already answered, but in case someone wants to use the actual device locale and not a hard-coded one:
Important, you need to pass a
String and not a
Locale object here.
If you want to have a custom date format, then you need to create your own switch/case based on all the locales you want to support.