DateFormat formatter = new SimpleDateFormat("MM/dd/yyyy' 'HH:mm:ss");
Date d = (Date)formatter.parse(dateTime);
System.out.println("date in controller "+d);
I get the output as
date in controller Mon Dec 31 16:04:57 IST 2012
Please suggest a method to output the date in MM/dd/yyyy HH:mm:ss
format.
Need the output in date format and not as string so as to store the output in datetime
field in mysql db
Need the output in date format and not as string so as to store the output in datetime field in mysql db
After the statement
Date d = (Date)formatter.parse(dateTime);
java.sql.Date sqldate = new java.sql.Date(d.getTime())
you have got a java.util.Date
object and you can store it as it is in mysql DB (column type : datetime).
However, when you are printing d
, it defaults to the .toString()
implementation. I think you expected some output like Date@ but the toString printed in user readable format thats why the confusion.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With