how to format 2013-05-15T10:00:00-07:00 to Date android -


i trying format date string date, , month/day it:

string strdate="2013-05-15t10:00:00-07:00"; simpledateformat dateformat = new simpledateformat(             "yyyy-mm-dd hh:mm:ss-z");      date converteddate = new date();     try {         converteddate = dateformat.parse(strdate);     } catch (parseexception e) {          e.printstacktrace();     }   simpledateformat sdfmonth = new simpledateformat("mm/dd");         string monthday= sdfmonth.format(converteddate); 

but returns me current month/day i.e 5/18. whats wrong?

3 things :

  • there mistake in format : 2013-05-15t10:00:00-07:00 has no meaning, should 2013-05-15t10:00:00-0700 (with no colon @ end, timezone defined in rfc 822. (look @ docs z).
  • change format yyyy-mm-dd't'hh:mm:ssz mentionned @blackbelt
  • you bad date because re-format date whatever happens during parsing. re-format in try block, if , if parsing worked.

----------update

    string strdate = "2013-05-15t10:00:00-0700";     simpledateformat dateformat = new simpledateformat("yyyy-mm-dd't'hh:mm:ssz");      date converteddate = new date();     try {         converteddate = dateformat.parse(strdate);         simpledateformat sdfmonth = new simpledateformat("mm/dd");         string monthday = sdfmonth.format(converteddate);     } catch (parseexception e) {         e.printstacktrace();     } 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -