• Post Reply Bookmark Topic Watch Topic
  • New Topic

Calendar With locale parm  RSS feed

 
Kevin Crays
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm confused by what the locale does here. It's purpose is clear for DateFormat.getinstance, but it doesn't seem to change the time, nor does it change the language, so what exactly is the point of calling Calendar.getInstance() with a locale?

It clearly doesn't do anything if I convert it to a date before printing. What am I missing?

Thanks,

Kevin
 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
TryWhere l.getLocale() returns a Locale object and calendar is a GregorianCalendar object.
[ June 28, 2006: Message edited by: Campbell Ritchie ]
 
Kevin Crays
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure if I was clear or I'm just not understanding your response, but I'm asking specifically what the point of instantiating a calendar object with a locale. For example



The code you posted shows what locale does in a format call, but the result of that call is unchanged, regardless of whether I instantiated the Calendar object with a Locale object or not.
 
Paul Clapham
Sheriff
Posts: 22828
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If your locale is one in which the Gregorian calendar is standardly used, then you'll get a GregorianCalendar object from that. And theoretically if there were other subclasses of Calendar -- such as an Islamic or Ethiopian or Japanese calendar -- then using for example Locale.JAPAN might return a Japanese calendar. But there aren't any other subclasses of Calendar, at least not in Java 5, so you always get a GregorianCalendar. It's a factory method.

(Later edit Calendar.getInstance(Locale.US) and Calendar.getInstance(Locale.FRANCE) do work differently -- for example they return different values from getFirstDayOfWeek().
[ June 29, 2006: Message edited by: Paul Clapham ]
 
Kevin Crays
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Paul Clapham:
If your locale is one in which the Gregorian calendar is standardly used, then you'll get a GregorianCalendar object from that. And theoretically if there were other subclasses of Calendar -- such as an Islamic or Ethiopian or Japanese calendar -- then using for example Locale.JAPAN might return a Japanese calendar. But there aren't any other subclasses of Calendar, at least not in Java 5, so you always get a GregorianCalendar. It's a factory method.


Thanks Paul. The class documentation doesn't really make that clear. So now I know....there's no point in it for now, but somewhere down the road that will change.

Thanks.

Kevin
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!