I want to display a hint how a date should be entered. For Germany it might look like
"Enter date in this format: dd.mm.yyy"
For the US
"Enter date in this format: mm/dd/yyyy"
I understand that with
DateFormat dateFormat = android.text.format.DateFormat.getDateFormat(context);
I can convert a date into a format matching the user's locale. But how would I get the day/month/year string for the hint?
And of course I would want the similar thing with a hint for time, too.
Thanks for any suggestions.
You can use the getBestDateTimePattern method of DateFormat:
note: assumes 24-hour format for the time. You might want to convert to all upper or lower case before presentation to the user.
I know you were asking for just the date, but this was as close as I can get. The internal rule is
localeData.getDateFormat(SHORT) + " " + localeData.getTimeFormat(SHORT)
so I guess as long as there is not a locale that has a date format with spaces on it, you can just split the string on a spaceWouldn't it be easier to get you date with a date picker: http://developer.android.com/guide/topics/ui/controls/pickers.html#DatePicker
If not, then take a look at this: https://stackoverflow.com/a/11093572/3965178
Try this: