android - Convert date into "17. December 2015" Format -


i getting date in form of "20150119" , want convert format like: "19. january 2015" .

how can convert date in such format.

i tried below code:

private void convertdate() {         string m_date = "20150119";         simpledateformat originalformat = new simpledateformat("yyyy.mm.dd");         try {             date date = originalformat.parse(m_date.tostring());             log.e("date is====", date.tolocalestring());         } catch (parseexception e) {             // todo auto-generated catch block             e.printstacktrace();         }      } 

but giving me error:

java.text.parseexception: unparseable date: "20150119" (at offset 8)

you need specify 2 formats: 1 parse input, 1 format output.

  1. the error occurs because string trying parse not match format specified in originalformat: 1 needs be

    simpledateformat originalformat = new simpledateformat("yyyymmdd"); 

    if want parse strings of format string m_date = "20150119";. parsing string format give date:

    date date = originalformat.parse(m_date); 
  2. then may use format output date:

    simpledateformat outputformat = new simpledateformat("dd. mmmm yyyy"); system.out.println("date: " + outputformat.format(date)); 

Comments

Popular posts from this blog

IF statement in MySQL trigger -

c++ - What does MSC in "// appease MSC" comments mean? -

javascript - Blogger related post gadget image Resize s72-c [ Need Expert Help ] -