Date format conversion as a Date object in a particular format in java

date, java

Solution

you need to use `df.format(Date)` method to get date in required format

Problem

I am finding the current time using `Date date3 = Calendar.getInstance().getTime();` This gives me `Thu Oct 25 11:42:22 IST 2012` Now I want my Date to be in the format `2012.10.25` and that too as a Date object and not a string. I tried using the below code ``` DateFormat df = new SimpleDateFormat("yyyy.MM.dd"); Date startDate = df.parse(c_date1); ``` But when I finally use `System.out.println(startDate.toString());` it again gives me `Thu Oct 25 00:00:00 IST 2012.` that is practically because the `toString()` function has been implemented in a way to show this format. So is there any other way to get the date as `2012.10.25` and that too as the Date format. Date object is required because it is to be saved in db as a date field.

Original source

Related problems