• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Java Datetime issue

 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
mm = minutes in hour (05 in your example).

MM = month in year (53 in your example).
 
It's never done THAT before. Explain it to me tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic