This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to format a date.

 
Anthony Smith
Ranch Hand
Posts: 285
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a Date object.

I want to print the date like this:

20050808

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)) +
String.valueOf((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
Posts: 61
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is a clean way to do this.

Take a look at SimpleDateFormat
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic