• 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

setting custom Date format globally

 
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Is it possible to set custom date format globally in desktop application?
Just like we set Look and Feel only once and the same is followed automatically throughout the application.
 
Mahesh Kedari
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could anyone please help me on this. I am unable to find anything on this even on net.
Right now I am converting date format wherever Im using Date function in my application.
 
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
You can set the default Locale by calling Locale.setDefault(...) but that will affect all the language- and country-specific settings, not just the date format.

You can format dates by using the java.text.SimpleDateFormat class, which will enable to you specify how dates should be formatted in detail.
 
Mahesh Kedari
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your reply.
Is it possible to set custom locale in which i can keep language as US english only and change the date format?
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Possibly, but you need more than just the locale. I've been checking it out a bit, and you need at least the following:
- the Locale
- a sub class of java.text.spi.DateFormatProvider
- a way to combine the two

Unfortunately, the latter is located in class sun.util.LocaleServiceProviderPool of which the source is not in the src.zip file in the JDK folder. Here is the calling code from DateFormat.get(int, int int, Locale):
flags is 1 for time, 2 for date and 3 for date/time. timeStyle and dateStyle are one of DateFormat.FULL, LONG, MEDIUM, SHORT or DEFAULT. loc is the Locale. DateFormatGetter is a private nested class:
It essentially only calls one of the methods of a DateFormatProvider instance, but the mapping is still somewhere in the LocaleServiceProviderPool. Perhaps you can read how to connect them in the Javadoc of java.util.spi.LocaleServiceProvider.
 
Mahesh Kedari
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Rob for your inputs...
Its working fine....!!
 
Rob Spoor
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you share how you matched the DateFormatProvider to the Locale? I think I know how you did it, but I'm not sure.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic