• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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,
 
Rancher
Posts: 4803
7
Mac OS X VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello! Pat Farrell, Thanks for your valuable response!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic