Could somebody tell me how can I get the default date and time format pattern(String) for specified locale(or default locale).
What I already found (Could be useful for somebody else):
-
How to get default locale.
Locale currentLocale= Locale.getDefault(); System.out.print(currentLocale.toString()); Result is "en_US" -
How to get decimal separator.
DecimalFormatSymbols decimalFormatSymbols = new DecimalFormatSymbols(currentLocale); System.out.print(decimalFormatSymbols.getDecimalSeparator()); Result is "." -
How to get the default Date and Time format pattern (String);
(do something) System.out.print(something); And got at output something like this: "dd/mm/yyyy" or "hh:mm:ss".. or other values for specified locale.
Thanks a lot.
UPD:
Found solution:
SimpleDateFormat simpleDateFormat = new SimpleDateFormat();
String dateLocalizedFormatPattern = simpleDateFormat.toLocalizedPattern();
The result of System.out.print(dateLocalizedFormatPattern)
on my device is "M/d/yy h:mm a".
Update
As Russian Bear mentions in his update to the question there is a
toLocalizedPattern()method inSimpleDateFormatthat returns the format string.Original answer
SimpleDateFormatuses the following code in it’s private constructor:So the actual format strings seems to be in a
ResourceBundleaccessed via theLocaleData.getDateFormatData()method.Unfortunately the
LocaleDataclass is a part of the internalsun.util.resourcespackage.