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

Date format

 
Johnny Sheppard
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't use Java for full fledged programming, but I use it to do math calculations and date calculations for an Interactive Voice Response system. Here is my problem. The date format I get back from the following code is formatted as such 3/3/08. The problem is I need to get this format to read 03/03/08. Can someone tell me how? Below is the code.

calEndDate = Java.util.GregorianCalendar(intYear, intMonth, intDay)

{
//ADD 3 MONTHS TO START DATE
calEndDate.add(calEndDate.MONTH, 2);
//SUBTRACT 1 DAY FROM END DATE
calEndDate.add(calEndDate.DATE, (-1));
//SET DATE TO GREGORIAN CALENDAR RESULT
java.util.Date dateEndDate = calEndDate.getTime();
// RETURN TO SCRIPT
return dateEndDate;
}
 
Rob Spoor
Sheriff
Pie
Posts: 20372
44
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check java.text.SimpleDateFormat.
 
Johnny Sheppard
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think that I tried that. Can you tell me what the syntax would be for my example?
Thanks,
 
Rob Spoor
Sheriff
Pie
Posts: 20372
44
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
DateFormat format = new SimpleDateFormat("dd/MM/yy");

Mind the capital MM - if you use lowercase, it will take the minutes.
 
Atulya Mahajan
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
DateFormat df = new SimpleDateFormat("dd/MM/yy");
Date date= new Date();
String dateStr= df.format(orig);
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic