It's not a secret anymore!
The moose likes Java in General and the fly likes Calendar.getInstance() vs. Calendar.getInstance(Locale.JAPAN) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Calendar.getInstance() vs. Calendar.getInstance(Locale.JAPAN)" Watch "Calendar.getInstance() vs. Calendar.getInstance(Locale.JAPAN)" New topic

Calendar.getInstance() vs. Calendar.getInstance(Locale.JAPAN)

Murly Kant

Joined: Oct 18, 2010
Posts: 5
Hello Experts!
I run the following program on my system:

import java.util.Date;
import java.util.Calendar;
import java.util.Locale;
class x{
public static void main(String[] args){

Calendar c = Calendar.getInstance();
Date d = c.getTime();

Calendar c2 = Calendar.getInstance(Locale.JAPAN);
Date d2 = c2.getTime();

printing d and d2 gives the same result, I don't understand then whats the difference between two? In which scenario I'll get different result.

Your valuable response will help me to understand the concept.
Thanks & Regards,
Pat Farrell

Joined: Aug 11, 2007
Posts: 4659

in Java, a Date or a Calendar does not have a timezone or format. Its simply the number of milliseconds since some particular time. All of the localization, time-zones, etc is done in the Format that helps with the input or output of the Date or Calendar.

Read the Javadocs for SimpleDateFormat for some basics. Its actually a complex problem. The naive implementation of Date within Java, and the sad fact that Date has not been deprecated has hurt many a programmer's productivity.
Murly Kant

Joined: Oct 18, 2010
Posts: 5
Hello! Pat Farrell, Thanks for your valuable response!
I agree. Here's the link:
subject: Calendar.getInstance() vs. Calendar.getInstance(Locale.JAPAN)
It's not a secret anymore!