| Author |
Java Datetime issue
|
Mike Boota
Ranch Hand
Joined: Jul 18, 2002
Posts: 82
|
|
Hi, I am trying to convert the date in "yyyymmddhhMMssSS" format to mill SimpleDateFormat sdf = new SimpleDateFormat( "yyyymmddhhMMssSS" ); java.util.Date javaDate = sdf.parse( "2007051811531845" ); java.sql.Timestamp ts11 = new java.sql.Timestamp(javaDate.getTime()); Now here when I do System.out I get the following value //1305731118045 Here I am saving the above timestamp in Oracle table String query_2 = "insert into tsdate values(?)"; PreparedStatement prepstat = dbConnection.prepareStatement( query_2 ); prepstat.setTimestamp( 1, ts11 ); rows = prepstat.executeUpdate(); now when I check the data in oracle table it is saved as 5/18/2011 11:05:19.045000 AM which is not correct as my original date is 2007 but here it's shown as 2011 And here I am reading it back again from the table: String selQuery = "Select tsdate from tsdate"; Statement s = dbConnection.createStatement(); ResultSet rs = s.executeQuery(selQuery); java.sql.Timestamp ts22 = rs.getTimestamp("tsdate"); long tsTime1 = ts22.getTime(); System.out.println("Value is: "+tsTime1); //1305731118045 Calendar cal = Calendar.getInstance(); DateFormat d = DateFormat.getInstance(); SimpleDateFormat sdf2 = new SimpleDateFormat( "yyyymmddhhMMssSS" ); System.out.println(sdf2.format(new Date(tsTime1))); //2011051811051845 Can anyone please tell what I am doing wrong: Thanks
|
MB<br />Sun Certified Programmer for Java2 Platform
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16480
|
|
mm = minutes in hour (05 in your example). MM = month in year (53 in your example).
|
 |
 |
|
|
subject: Java Datetime issue
|
|
|