File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Java Datetime issue 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 » Java » Beginning Java
Bookmark "Java Datetime issue" Watch "Java Datetime issue" New topic
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: 18113
    
    8

mm = minutes in hour (05 in your example).

MM = month in year (53 in your example).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java Datetime issue
 
Similar Threads
help me in time comparison
Oracle Timestamps and java.
input file and output file
How to fetch Date Field from excel sheet in Java
SimpleDateFormat and locale