• Post Reply Bookmark Topic Watch Topic
  • New Topic

Default date 1970-01-01 being displayed in SQL  RSS feed

 
Vishal Hegde
Ranch Hand
Posts: 1078
Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I harcoded a variable creation data in a java file which in turn inserts into the table but the issue here is its inserting date with the date value:1970-01-01

Date creationdate=new Date(2013-02-10);

Please advice where I am going wrong.
 
Rob Spoor
Sheriff
Posts: 21117
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If that's really your line of code, it's not doing what you want it to. First you subtract 2 (octal) and 10 from 2013, leaving 2011. You then create a new Date object that is 2011 milliseconds (or just over 2 seconds) past midnight on January 1st 1970.

you should check out DateFormat and SimpleDateFormat if you want to convert any String into a Date, and Calendar or GregorianCalendar if you want to create a Date object for a specific date/time.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!