Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Calendar.getInstance(locale) not working

 
Vijay Tyagi
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • 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
 
Darryl Burke
Bartender
Posts: 5148
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • 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
  • 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 ?
 
Mohamed Sanaulla
Saloon Keeper
Posts: 3159
33
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • 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.
 
Wayan Saryada
Ranch Hand
Posts: 105
IntelliJ IDE MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • 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.

 
Campbell Ritchie
Sheriff
Pie
Posts: 50277
80
  • Mark post as helpful
  • send pies
  • 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
Sheriff
Pie
Posts: 50277
80
  • Mark post as helpful
  • send pies
  • 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.
 
Rob Spoor
Sheriff
Pie
Posts: 20669
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic