title: How to format Oracle date and timestamp type values in Java?
body: <p>I have date and timestamp type fields in oracle db, I need to retrieve these values and map them to my object field. Though I format the values I do not get the expected result. Here is the my code snippet.</p>
  
  <pre><code>import java.util.Date;
  public class Operation{
  private Date created;
  private Date valueDate;
  
  public Date getValueDate() {
      return this.valueDate;
  }
  public void setValueDate(Date valueDate) {
  this.valueDate = valueDate;
  }
  public Date getCreated() {
      return this.valueDate;
  }
  public void setCreated(Date created) {
  this.created= created;
  }
  }
  
  
  //here starts code snippet to call db method
  
  SimpleDateFormat df1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSSSSS");
  SimpleDateFormat df2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  
  String formatCreated = df1.format(result.getTimestamp(22)); //Input from db: 23-FEB-18 06.17.42.302680 PM 
  //OutputFormat 2018-02-23 18:17:42.000302  
  String formatValueDate = df2.format(result.getTimestamp(23));//Input from db:23.02.2018 18:17:42 
  //OutputFormat 2018-02-23 18:17:42
  Operation op = new Operartion();
  op.setCreated(df1.parse(formatCreated)) //Output Fri Feb 23 18:17:42 GMT+04:00 2018
  op.setCreated(df1.parse(formatValuedate)) //Output Fri Feb 23 18:17:42 GMT+04:00 2018
  </code></pre>
  
  <p>Any help appreciated!</p>