This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
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 REST with Spring (video course) this week in the Spring 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
subject: How to format a date.
It's not a secret anymore!