aspose 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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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: 1050

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: 19541
    
  16

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
 
Similar Threads
Dates
Specify Date as 0000-00-00
Date Formatting
Customizing java Calendar
Date 01/01/1970 returning non-zero value for time