Printing a formatted date in Java

Printing a date out in the certain format is easy in java - you need to use the SimpleDateFormat class - there is an example below


public void printFormattedDate()
{
        Date theDate = new GregorianCalendar().getTime();

        SimpleDateFormat format = new SimpleDateFormat(
                "EEE MMM dd HH:mm:ss zzz yyyy");
        System.out.println("The date formatted is " + format.format(theDate));

}