elfar
elfar

Reputation: 481

date values saved to database are different with what they should be

Using hibernate and annotation, I am trying to save values to a table that has a date column (I am using Mysql). The problem is that the date values saved to database are somehow different with what the should be. first I create a new java.sql.Date e.g.

Date date = new Date(2013, 10, 1);

but what is saved into my table is:

3913-02-10

Upvotes: 0

Views: 105

Answers (1)

JB Nizet
JB Nizet

Reputation: 692231

Months are 0 based (so 1 is February), and years are 1900-based (so 2013 is 3913). That's explained in the Date javadoc. The javadoc also says that this constructor is deprecated, so you shouldn't use it anyway.

Upvotes: 2

Related Questions