Friday, 15 April 2011

Android Date format conversion 71 -



Android Date format conversion 71 -

i have date in 02/21/2013 04:52:10 pm format.

how convert mm-dd-yyyy hh:mm. tried few things keeps throwing error

java.text.parseexception: unparseable date: "02/21/2013 04:52:10 pm" (at offset 2)

i need help date format expert. thanks

try one:

dateformat inputformat = new simpledateformat("mm/dd/yyyy hh:mm:ss a", locale.getdefault()); dateformat outputformat = new simpledateformat("mm-dd-yyyy hh:mm", locale.getdefault()); seek { system.out.println("converted: " + outputformat.format(inputformat.parse("02/21/2013 04:52:10 pm"))); } grab (parseexception e) { e.printstacktrace(); }

output: 01-21-2013 16:52

checkout http://docs.oracle.com/javase/1.4.2/docs/api/java/text/simpledateformat.html more

cheers

android

No comments:

Post a Comment