0

I want to store date in DB in e.g. 13/09/2016 06:48:23 format.

My DB table column datatype for "publishDate" column is Date.

In java I am doing as ,

    SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss");
    String strDate = sdf.format(new Date());
    System.out.println(strDate);  //13/09/2016 06:48:23

But I want to store this String date into publishDate column which has Date datatype.

I tried like ,

    Date publishDate = sdf.parse(strDate);
    System.out.println(publishDate); //Tue Sep 13 06:48:23 IST 2016 

Output is not in required format (required format is 13/09/2016 06:48:23).

Can someone please suggest what I am missing here.

Thanks in advance.

  • I have seen already answered question for the same. but it didnt help me :( . I want to store it in 13/09/2016 06:48:23 format , which I am not understanding – Dhananjay Sep 13 '16 at 16:44
  • or as per this link http://stackoverflow.com/questions/4167485/parsing-a-string-into-date-with-dateformat-not-parsing-correctly will it store correctly my publishDate in DB ? since above I am doing system.out.pritnln(publishDate) . But in DB it will automatically store publishDate ? – Dhananjay Sep 13 '16 at 16:54
  • can someone please help in this ? – Dhananjay Sep 13 '16 at 17:15
  • I'm confused by your question. A date is a date, period. Don't think of different string representations of the same date as being different dates. A "format" refers to how you want to show the date (as a string). – tbone Sep 13 '16 at 19:56

0 Answers0