PDA

View Full Version : Forcing Datepicker to 4 digit year



acrowley
11 Jan 2012, 9:24 AM
I have implemented the locale and my application now successfully formats the dates based on the locale loaded -> i.e. US : mm/dd/yy and SG: dd/mm/yy

My next problem is to force this to use yyyy which doesnt seem to work by default using the locales. I would like to force my datepickers to return the proper Month/Day formatting as returned by the locale setup and use a 4 digit year.

Any Ideas?

Thanks again.

acrowley
11 Jan 2012, 11:25 AM
In case anyone else runs into this issue here is what I did:

Extended the DateField class with my own called oaDateField... here is the constructor (and all this class does):
public oaDateField(){
super();
String format = this.getPropertyEditor().getFormat().getPattern();
//force the 4 digit year
if(format.indexOf("yyyy") == -1){
format = format.replace("yy", "yyyy");
}
this.getPropertyEditor().setFormat(DateTimeFormat.getFormat(format));
this.setFormatValue(true);
}

This will use my locale settings properly for the date and month, but continue to display using the yyyy year format.