user26270
user26270

Reputation: 7084

How do I use a common, custom DateTimeFormat in GWT in different locales?

We have a calendar widget which accepts a few date formats. We would like to add the format 'MM-dd-yyyy' for US-based clients. But in other locales, this format could be interpreted as 'dd-MM-yyyy' (or other interpretations). The docs say to "use the default formats and let the localization mechanism in the DateTimeFormat do the work for you."

Would CustomDateTimeFormat be my solution? I've looked at it, but the usage is unclear and the docs almost non-existent.

Upvotes: 2

Views: 998

Answers (1)

David Levesque
David Levesque

Reputation: 22451

I think that PredefinedFormat.DATE_MEDIUM would do what you want, e.g.:

DateTimeFormat dateFormat = DateTimeFormat.getFormat(PredefinedFormat.DATE_MEDIUM);

The date format will change according to the GWT locale.

By the way, the examples provided in the doc that you linked to are using a deprecated syntax. It has been replaced by PredefinedFormat.

Upvotes: 1

Related Questions