This week's book giveaway is in the JavaFX forum.
We're giving away four copies of Introducing JavaFX 8 Programming and have Herbert Schildt on-line!
See this thread for details.
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


Win a copy of Introducing JavaFX 8 Programming this week in the JavaFX forum!
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: 20128
    
  30

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


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 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
 
It's not a secret anymore!