Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7894393
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:23:06+00:00 2026-06-03T07:23:06+00:00

The below code when run with JDK5(1.5.0_09) prints Fri May 03 00:00:00 GMT 3912

  • 0

The below code when run with JDK5(1.5.0_09) prints

Fri May 03 00:00:00 GMT 3912 
5/3/12 5:30 AM

and when run with JDK6(1.6.0_23) prints

Fri May 03 00:00:00 IST 3912
5/3/12 12:00 AM

Obviously the difference is because of the timezone used then the Date object is created. But doesn’t this cause problems for existing code when the JDK is upgraded? Is this behavior documented somewhere or am I missing something?

    class TimeTest {

    public static void main(String[] args) {

        Date d = new Date(2012, 04, 3);
        Locale l = new Locale("en", "US","");   
        DateFormat df= DateFormat.getDateTimeInstance(DateFormat.SHORT,  DateFormat.SHORT, l );
        TimeZone t = TimeZone.getTimeZone("Asia/Calcutta");
        df.setTimeZone(t);      
        System.out.println(d);
        System.out.println(df.format(d));

    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T07:23:08+00:00Added an answer on June 3, 2026 at 7:23 am

    The strange year 3192 is arising because that deprecated Date constructor assumes you are using a 2-digit year with 0 meaning 1900. It adds 1900 to the year number.

    The difference in the timezones is not the fault of the Date constructor. Your code is using TimeZone.getTimeZone("Asia/Calcutta") to get the timezone. That method is documented as returning the GMT timezone if it doesn’t recognize the timezone string. It would appear that Sun ADDED support for more timezones in Java 1.6. (Most people would view this as a good thing rather than as a portability concern.)

    I haven’t tried it, but the following should be sufficient to insulate yourself against using GMT when your requested zone id is unrecognised.

        public TimeZone getZone(String id) {
            TimeZone tz = TimeZone.getTimeZone();
            if (!tz.getID().equals(id)) {
                throw new IllegalArgumentException("unrecognized zone " + id);
            }
            return tz;
        }    
    

    In summary, your code is broken in two respects:

    • It is using a deprecated constructor.
    • It is assuming that getTimeZone will understand all of your timezone Strings, and this is clearly not the case for Java 1.5.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I run the below code, everything goes great until I change the value
I am trying to run the code below but it keeps locking up my
the code below works fine but it takes an absolute age to run. How
I'm trying to run the below-mentioned code in VB(Excel Macro) but I'm stuck with
Any ideas given the code below why the highlight is being triggered to run
When I run the following code, I get the exception below: ''# NOTE: ExcelApp
When I run the code below I get: Thank you for joining, ['cars', 'gas',
whenever i run the code below it occurs to me I have made a
I'm trying to run the code below to insert a whole lot of records
I keep getting this whenever I run the below code: Fatal error: Call to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.