How do I set default date format (not locale)

I know I can set locale on UI.

However that’s not what I want, I want to see the date format for date controls to

yyyy-MM-dd

i.e. iso8601

Is there any way to do this, apart from creating own fields and setting data format on them directly? (I’m doing this already, just seems a bit sucky just to ensure that use a certain format throughout the app)

Thanks.

I’m not sure that’s possible. After all formats like this depends on Locale which by default is the one of the OS, and user specific setting. Your users should be in control of how they want to see it, depending on how they are used to. Usually for display purposes you should use constants like DateFormat.SHORT, DateFormat.MEDIUM, etc.

But anyway, if you want to do something more elegant then to set the data format on each field, please consider creating a factory which provides DateField objects. Create all your DateField, InlineDateField, PopupDateField objects using this factory. Doing it so, you’ll need to write only one line of code to set the dateFormat.

[code]
public class DateFields {

// Ensure factory pattern.
private DateFields() {
}

private static final String DATE_FORMAT = “yyyy-MM-dd”;

/**

  • Don’t forget comments.
    */
    public static DateField createDateField() {
    DateField dateField = new DateField();
    initDateFormat(dateField);
    return dateField;
    }

public static DateField createInlineDateField() {
InlineDateField dateField = new InlineDateField();
initDateFormat(dateField);
return dateField;
}

public static DateField createPopupDateField() {
PopupDateField dateField = new PopupDateField();
initDateFormat(dateField);
return dateField;
}

private static void initDateFormat(DateField dateField) {
dateField.setDateFormat(DATE_FORMAT);
}

}
[/code]Hope this help!

No, its not up to my users what format they see. Trust me that I know my app well enough.

I already know about Factories. I said “apart from creating own fields and setting data format on them directly”.

I suspected as much, was just looking for an existing mechanism, like setLocale.

If Locale could let me set the format to ISO8601 then I’d use one of those. But I can’t to the best of my knowledge.