• 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

Calendar.getInstance(locale) not working

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






In above code, I pass a locale to Calendar.getInstance(), but the date displayed is

not locale specific

What is wrong in this code ? I want to display locale specific date without using DateFormat

Please answer,
Thanks
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Vijay Tyagi wrote:I want to display locale specific date without using DateFormat.



Now why would you want to do that?
 
Vijay Tyagi
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Darryl Burke wrote:

Vijay Tyagi wrote:I want to display locale specific date without using DateFormat.



Now why would you want to do that?




Actually, I want to understand the use of Calendar c=Calendar.getInstance(new locale("fr"));

I pass a locale there ,while creating a Calendar instance
Now how do I make use of it ?
 
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Vijay Tyagi wrote:

Darryl Burke wrote:

Vijay Tyagi wrote:I want to display locale specific date without using DateFormat.



Now why would you want to do that?




Actually, I want to understand the use of Calendar c=Calendar.getInstance(new locale("fr"));

I pass a locale there ,while creating a Calendar instance
Now how do I make use of it ?


You can make use of Locale.FRANCE instead of new Locale("fr"). I dont know if that would matter, but its good to use the JDK constant.
 
Ranch Hand
Posts: 119
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you create an instance of Calendar by specifying a locale you will get a calender object for that specific locale. For instance, getting calendar instance using a Locale.FRANCE will set the first day of week to MONDAY, while using a Locale.US will give you SUNDAY as the first day of week.

 
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don’t think there is anything wrong with the Locale, although the constant is usually better style. The arguments appear to be case-insensitive, because I tried it with FR and fr. I think the problem is with how Calendar displays the information.
[edit]Look at the Calendar#toString() method and see whether that provides any useful information.[/edit]
 
Campbell Ritchie
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh, you are not printing the Calendar object in that code at all. You need the Date#toString() method. But remember, date objects do not contain any locale-specific information.
 
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

Mohamed Sanaulla wrote:You can make use of Locale.FRANCE instead of new Locale("fr").


Locale.FRANCE is not equal to a new Locale("fr"). Locale.FRANCE is fr_FR. You meant Locale.FRENCH.
 
reply
    Bookmark Topic Watch Topic
  • New Topic