How to get default Locale Date Format Pattern?

I am using a JXDatePicker component to present date fields in my application(http://www.javanus.com/AssistWeb). The application supports seven different languages at the moment. Translation is using resource bundles and it works fine. I also want to localize date fields to present date in a localized format.

It is very easy to convert a date in a paricular format in java. SimpleDateFormat is easy to use, programmer should only pass a particular date format  (dd/MM/yy or dd.MM.yyyy).

The problem arise when I want to provide a date format for a jXDatePicker component. I did not know how to set the proper format for JXDatePicker according to selected language. I just need a localized date format pattern to set the format for jXdatePicker. After a few hours I found the solution I would like to share you.

//inicialization

jXDatePickerDateField.setDate(new java.util.Date());

Solution:

Locale locale = Locale.getDefault();

String datePattern = ((SimpleDateFormat)DateFormat.getDateInstance(SimpleDateFormat.MEDIUM,locale)).toPattern();

jXDatePickerDatum.setFormats(datePattern);

Tags: , , , , ,

Leave a Reply