Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Murly Kant
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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();
System.out.println(d);

Calendar c2 = Calendar.getInstance(Locale.JAPAN);
Date d2 = c2.getTime();
System.out.println(d2);
}
}

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
Rancher
Posts: 4678
7
Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello! Pat Farrell, Thanks for your valuable response!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic