I have a requirement. I want to convert Date object to formatted Date object.
I mean,
`Date d = new Date();System.out.println(d);'
Output: Thu Apr 05 11:28:32 GMT+05:30 2012
I want output to be like 05/APR/2012. And the output object must be Date and not String. If at all you are not clear , I'll post more clearly
Thank You.
Don't need any third party APIs, just use DateFormat to parse/format Dates by providing date format pattern. The sample code would be:
Date date = new Date();
DateFormat df = new SimpleDateFormat("dd/MMM/yyyy");
String formattedDate = df.format(date);
System.out.println(formattedDate.toUpperCase());
Demo run here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With