aspose file tools*
The moose likes Beginning Java and the fly likes Date format Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Date format" Watch "Date format" New topic
Author

Date format

Johnny Sheppard
Greenhorn

Joined: Dec 18, 2007
Posts: 2
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

Joined: Oct 27, 2005
Posts: 19760
    
  20

Check java.text.SimpleDateFormat.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Johnny Sheppard
Greenhorn

Joined: Dec 18, 2007
Posts: 2
I think that I tried that. Can you tell me what the syntax would be for my example?
Thanks,
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19760
    
  20

DateFormat format = new SimpleDateFormat("dd/MM/yy");

Mind the capital MM - if you use lowercase, it will take the minutes.
Atulya Mahajan
Greenhorn

Joined: Dec 16, 2007
Posts: 14
DateFormat df = new SimpleDateFormat("dd/MM/yy");
Date date= new Date();
String dateStr= df.format(orig);
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Date format