I have a SimleDateFormat
like this
SimpleDateFormat format = new SimpleDateFormat(\"MMM dd,yyyy hh:mm\");
String date = format.format(Date.parse(p
The accepted answer here suggests to use more than one SimpleDateFormat
, but it's possible to do this using one SimpleDateFormat
instance and calling applyPattern
.
Note: I believe this post would also be helpful for those who were searching for setPattern() just like me.
Date date=new Date();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat();
simpleDateFormat.applyPattern("dd");
System.out.println("Day : " + simpleDateFormat.format(date));
simpleDateFormat.applyPattern("MMM");
System.out.println("Month : " + simpleDateFormat.format(date));
simpleDateFormat.applyPattern("yyyy");
System.out.println("Year : " + simpleDateFormat.format(date));