What do you understand by Formatting ? it's simply the way in which something is arranged or set out. If i say format the document i don't actually change the type of the document i change how it's organised to the way how i want.
While parsing is changing some kind of data into another kind of data.
so here according to your requirement you are changing string to date so first you need to parse and then format it according to your desired format.
One way to do it
Scanner sc=new Scanner(System.in);
System.out.println("Enter the date");
String stringDate=sc.nextLine();
DateFormat dateFormat=new SimpleDateFormat("dd/MM/yyyy");//give it your desired format
Date date=new Date();
try {
date=dateFormat.parse(stringDate);
} catch (ParseException e) {
e.printStackTrace();
}
Edit: Since in comment you says.. you want current date in to be formatted in one line try this it will work.
import java.text.SimpleDateFormat;
import java.util.Date;
public class IntermTest {
public static void main(String...strings ){
System.out.println((new SimpleDateFormat("yyyyMMdd")).format(new Date()));
}
}