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

Convert Calendar to String

Bob Smith
Greenhorn

Joined: Sep 10, 2008
Posts: 12
How do I convert a Calendar to a String? I would like it in the following format MM/DD/YYYY.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19785
    
  20

Calendar.getTime() + (Simple)DateFormat is the way to go.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Bob Smith
Greenhorn

Joined: Sep 10, 2008
Posts: 12
Thanks, I got it to work

String strdate = null;

SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");

if (calendardate != null) {
strdate = sdf.format(calendardate.getTime());
}
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Convert Calendar to String