3
 public java.sql.Date getDate()
{
    java.sql.Date date = new java.sql.Date(2001, 10, 10);
    return date;

}

this function is in calendar class that own wrote it.

now in another class i wrote :

calendar c = new calendare();
java.sql.date d = c.getDate();

what value must store in d?it must be 2001,10,10 but it is 3901,11,10!!!!! why? please help me in solving it.

3 Answers 3

2

Try:

java.sql.Date date = new java.sql.Date(2001 - 1900, 10, 10);

See java.sql.Date which says:

year - the year minus 1900; must be 0 to 8099. (Note that 8099 is 9999 minus 1900.)

That constructor is deprecated. You should prefer to use the other java.sql.Date constructor.

Sign up to request clarification or add additional context in comments.

Comments

2

This is from the docs for java.sql.Date

year - the year minus 1900; must be 0 to 8099. (Note that 8099 is 9999 minus 1900.)
month - 0 to 11
day - 1 to 31

Also this constructor is deprecated. The year value is added tp 1900

Comments

0

First, that constructor is deprecated, you shouldn't use it.

Second, the JavaDoc mentions:

Parameters:
    year - the year minus 1900; must be 0 to 8099. 
    (Note that 8099 is 9999 minus 1900.)

So according to the docs, you did specify the year 2001 + 1900 which is 3901 :-)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.