File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Calendar.getInstance(locale)  not  working   Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Calendar.getInstance(locale)  not  working   " Watch "Calendar.getInstance(locale)  not  working   " New topic
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: 4523
    
    5

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
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3064
    
  33

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
Wayan Saryada
Ranch Hand

Joined: Feb 05, 2004
Posts: 104

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: 38007
    
  22
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: 38007
    
  22
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: 19653
    
  18

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 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
 
subject: Calendar.getInstance(locale) not working
 
Similar Threads
NumberFormat
One More to the K&B Errata log...Ch 6 Dates related
Locale Class
Finding Elapsed Time
Calendar with Locale