Java Date format example - Format a Date so humans can read it

Java Date format FAQ: Can you show me how to format a Java Date object in a human-readable format?

It's pretty easy to get a Date in a Java program, but it takes a little more work to print a Date in a human-readable format. This article shows how to print a date in a human-readable format.

Java Date format example

Here's a snippet of Java date formatting code I'm working on right now:

if (col==1)
{
  SimpleDateFormat sdf = new SimpleDateFormat("EEE, d MMM yyyy, hh:mm aaa");
  return sdf.format(model.getDate());
}

As you can see, the only things you really need are a Date, a Java SimpleDateFormat object, and a Java pattern you want to use for printing.

Java Data format and my Java SimpleDateFormat class

You can see how to create a Java SimpleDateFormat in the snippet above. For all of your SimpleDateFormat pattern needs, check out this URL on Sun's web site: