John Error John Error - 3 months ago 18
Android Question

Get day, month and year separately using SimpleDateFormat

I have a

SimleDateFormat
like this

SimpleDateFormat format = new SimpleDateFormat("MMM dd,yyyy hh:mm");
String date = format.format(Date.parse(payback.creationDate.date));


I'm giving date with the format like
"Jan,23,2014"
.

Now, I want to get day, month and year separately. How can I implement this?

Answer

If you need to get the values separately, then use more than one SimpleDateFormat.

SimpleDateFormat dayFormat = new SimpleDateFormat("dd");
String day = dayFormat.format(Date.parse(payback.creationDate.date));

SimpleDateFormat monthFormat = new SimpleDateFormat("MM");
String month = monthFormat .format(Date.parse(payback.creationDate.date));

etc.

Comments