Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Date format

 
Johnny Sheppard
Greenhorn
Posts: 2
  • 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: 20495
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check java.text.SimpleDateFormat.
 
Johnny Sheppard
Greenhorn
Posts: 2
  • 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: 20495
54
Chrome Eclipse IDE Java Windows
  • 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
  • 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);
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic