java - Convert string to Date -
i have string
string ackwarddate="2012-10-30t19:14:58"; i need convert date format.then tried this
ackwarddate=ackwarddate.replace("t", " "); simpledateformat formatter = new simpledateformat("yyyy-mm-dd hh:mm:ss"); try { date date = formatter.parse(ackwarddate); system.out.println(date); system.out.println(formatter.format(date)); } catch (parseexception e) { e.printstacktrace(); } it working fine. there other method?
you can include t in date format. , looking @ ackwarddate string, need use hh instead of hh has 24-hour format , represented h.
string ackwarddate="2012-10-30t19:14:58"; // ackwarddate=ackwarddate.replace("t", " "); // not needed anymore simpledateformat formatter = new simpledateformat("yyyy-mm-dd't'hh:mm:ss"); simpledateformat docs should understand more patterns available.
Comments
Post a Comment