• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

DateLocaleConverter not using supplied pattern

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Friends,
Apprreciate your help to resolve this issue.

I am using BeanUtils.copyProperties to populate my DTO from my form bean. I am using DateLocaleConverter to convert date string of my formbean to util date of DTO.
Somehow DateLocaleConverter does not use the format I am sending and gives me date in some other default format. I have registered DateLocaleConverter and it is getting invoked.

String pattern = "MM/dd/yy";
Locale locale = Locale.getDefault();
DateLocaleConverter converter = new DateLocaleConverter(locale, pattern);

Any help is appreciated.
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The only area of ambiguity might be the month and day getting mixed up.
For example, when the date 10/12/06 is converted, does it get converted to October 12, or to December 10?

If this is being translated correctly, DateLocaleConverter is working. A java.util.Date doesn't have a format. If BeanUtils is translating your String into a java.util.Date, it's doing its job. You can then format the date however you want.

One thing you may not be aware of is that DateLocaleConverter only handles the String to Object conversion, not the object to String conversion. If you want the java.util.Date to be displayed in a specific format, you will have to use java.text.SimpleDateFormat to format the date string the way you want it.
 
H Ritwick
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your reply.
DateLocaleConverter is converting 10/12/2006 as Thu Oct 12 00:00:00 PDT 2006. Good news.
I am passing pattern as MM/dd/yyyy and DateLocaleConverter has a parse() method which is using SimpleDateFormat to format the date in the supplied pattern. Anyway, I will try writing a CustomDateConverter and formatting. This should work converting either way right?
Thanks
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From what I read in the JavaDocs, the converters only affect the conversion from String to Object, not the other way around. Go ahead and play with it, though, and let us know what works and what doesn't.
 
reply
    Bookmark Topic Watch Topic
  • New Topic