• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

DateFormat getPattern

 
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys,

I'm looking for a way to get the date pattern from the DateFormat class. They have a number of localized styles, but I can't seem to work out how to get the actual pattern string. This seems to be supported in the SimpleDateFormat class, but not DateFormat.

So, for example, what is the DateFormat.MEDIUM pattern for Japan? I'd like to do this so my application can display the pattern it is going to apply to the user.

Any help is much appreciated.

Cheers,

Steve
 
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you look at the source for DateFormat calling DataFormat.getInstance()/getDateInstance()/getDateTimeInstance() calls SimpleDateFormat internally. So you can check to make sure its an instance of SimpleDateFormat and cast it and make the call to get the pattern.

Also all the pattern format strings are stored in the LocaleData

 
Steve Wood
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very much - that's superb.

Cheers,

Steve
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just a warning:

Note that Tim's solution is not guaranteed to work on future versions of Java. The API documentation (which is the spec) does not say that DateFormat.getInstance() returns a SimpleDateFormat. In fact, in a future version of Java the implementation might be changed and your program won't work anymore if it does change.
[ December 08, 2006: Message edited by: Jesper Young ]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic