views:

234

answers:

1

Maybe I'm going about this all wrong but here goes...

I'm trying to allow users of my Portlet app to input a date in whatever their localized format would normally be. I plan to parse the string date using a SimpleDateFormat object based on the user's current Locale on the backend.

I'm pretty sure that part will work (right?) but I'm confused on what the easiest way is to display the "helper" text that goes with the form field in the UI.

E.g.
Start Date (mm/dd/yyyy)
versus
Start Date (dd/mm/yyyy)

Is there a way to get that information from the localized formatter somehow that I'm missing? The only other alternative I can think of at this point is to add that text to the property files for translation into each language but it just seems like that shouldn't be necessary.

I guess even if I can get t

A: 

Have you tried SimpleDateFormat.toLocalizedPattern()?

Chase Seibert
Hi Chase,Thanks for your suggestion. I did notice that method but the problems I can see are:1. You have to use SimpleDateFormat instead of DateFormat.getDateInstance. To provide the Locale to SimpleDateFormat I have to provide it the pattern. The only way I can see to do that is kind of kludgy... basically something like:DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, Locale.US);String pattern = ((SimpleDateFormat)df).toLocalizedPattern();2. I can't figure out (in any case) how to get around the 2-digit year that is forced by DateFormat.SHORT. I'd prefer yyyy.
Brian McManus