How to display current date as

Saturday, November 19, 2011

Use : java.text.SimpleDateFormat

Date now = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("EEEE, MMMM dd, yyyy");
String s = sdf.format(now);
System.out.println(s);

Try to experiment by changing the number of 'E's and 'M'
Check this example:

Date now = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("EEE, MMM dd, yyyy");
String s = sdf.format(now);
System.out.println(s);

Check the API for additional format options. Try to experiment a bit with the Date and Time Patterns

You can do the oppositte with the parse method:

String s = "11-19-2011";
SimpleDateFormat sdf = new SimpleDateFormat("MM-dd-yyyy");

Date d = sdf.parse(s);

System.out.println(d);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.