| Author |
Calendar.getInstance(locale) not working
|
Vijay Tyagi
Ranch Hand
Joined: Feb 15, 2010
Posts: 52
|
|
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
Joined: May 03, 2008
Posts: 4165
|
|
Vijay Tyagi wrote:I want to display locale specific date without using DateFormat.
Now why would you want to do that?
|
luck, db
There are no new questions, but there may be new answers.
|
 |
Vijay Tyagi
Ranch Hand
Joined: Feb 15, 2010
Posts: 52
|
|
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
Bartender
Joined: Sep 08, 2007
Posts: 2927
|
|
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.
|
Mohamed Sanaulla | My Blog
|
 |
I Wayan Saryada
Ranch Hand
Joined: Feb 05, 2004
Posts: 83
|
|
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.
|
Website: Learn Java by Examples
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32675
|
|
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
Joined: Oct 13, 2005
Posts: 32675
|
|
|
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
Joined: Oct 27, 2005
Posts: 19216
|
|
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.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
 |
|
|
subject: Calendar.getInstance(locale) not working
|
|
|