how to change date format in java? -
i getting date input string in format dd-mm-yy
through jsp page. because format better understand . want store date in yyyy-mm-dd hh:mm:ss
format in database. using following code.
try { string s="30-04-2013"; simpledateformat ft = new simpledateformat("yyyy-mm-dd hh:mm:ss"); d1=new simpledateformat("yyyy-mm-dd").parse(s); system.out.println(d1); system.out.println(ft.format(d1)); } catch(exception e) { system.out.println("exception:"+e); }
my jsp date format dd-mm-yy
, gives answer as
tue oct 04 00:00:00 ist 35 0035-10-04 00:00:00
what mistake? can tell me please
thank you.
d1=new simpledateformat("yyyy-mm-dd").parse(s);
should
d1=new simpledateformat("dd-mm-yyyy").parse(s);
because input date string you've provided string s="30-04-2013";
of format, dd-mm-yyyy
. hence, parse this, need give dd-mm-yyyy
format in sdf.
Comments
Post a Comment