File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes How to format a date. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to format a date." Watch "How to format a date." New topic

How to format a date.

Anthony Smith
Ranch Hand

Joined: Sep 10, 2001
Posts: 285
I have a Date object.

I want to print the date like this:


I use:

Calendar c = Calendar.getInstance();
c.setTime(shipDate1); //shipDate is my Date Objecy

String date = String.valueOf(c.get(Calendar.YEAR)) + String.valueOf(c.get(Calendar.DAY_OF_MONTH)) +

The 0's from the day and month keep getting trimmed. There has to be a clean way to do this.
Richard Anderson
Ranch Hand

Joined: May 20, 2005
Posts: 61
There is a clean way to do this.

Take a look at SimpleDateFormat

-Rich, SCJP 1.4
I agree. Here's the link:
subject: How to format a date.
It's not a secret anymore!