Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

conversion from Date ojbect to Date object

Tags:

java

date

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.

like image 725
Vipul Avatar asked May 15 '26 00:05

Vipul


1 Answers

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.

like image 128
JMelnik Avatar answered May 17 '26 12:05

JMelnik



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!