File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Default date 1970-01-01 being displayed in SQL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Default date 1970-01-01 being displayed in SQL" Watch "Default date 1970-01-01 being displayed in SQL" New topic
Author

Default date 1970-01-01 being displayed in SQL

Vishal Hegde
Ranch Hand

Joined: Aug 01, 2009
Posts: 1055

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.


http://www.lifesbizzare.blogspot.com || OCJP:81%
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19718
    
  20

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Default date 1970-01-01 being displayed in SQL