1
java.sql.Date date = java.sql.Date.valueOf(
    jObject.getString(AppConstants.KEY_COMMENT_DATE)
);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MMMMM YYYYY");
try {
    simpleDateFormat.parse(
        jObject.getString(AppConstants.KEY_COMMENT_DATE)
    );
} catch (ParseException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

I am having date in 2015-03-05 03:20:13 format from webservice, I want to format and separate out month, year and other all.

zessx
  • 68,042
  • 28
  • 135
  • 158
Arth Tilva
  • 2,496
  • 22
  • 40

1 Answers1

0

Try following

DateFormat df = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
java.util.Date date = df.parse("2015-03-05 03:20:13");
Brijesh Bhatt
  • 3,810
  • 3
  • 18
  • 34
  • I used this and using date object i called date.getMonth().but it is throwing unparsable date i.e. parse exception – Arth Tilva Mar 09 '15 at 10:44
  • Make the H capital in date format string ..see above I have edited in my answer. – Brijesh Bhatt Mar 09 '15 at 10:50
  • Is there any way to get name of month from month no. like 1-> January...???I studied util and date library long before...thanks – Arth Tilva Mar 09 '15 at 11:04
  • @ArthTilva , take a look at this, http://stackoverflow.com/questions/1038570/how-can-i-convert-an-integer-to-localized-month-name-in-java – The Coder Mar 09 '15 at 11:06
  • java.util.date will give you month no from 0-11 if you want to get the full month initiate one more Simpledateformate instance with format string MMMM then use method sdf.format(date) – Brijesh Bhatt Mar 09 '15 at 11:08