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

Convert Calendar to String

 
Bob Smith
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do I convert a Calendar to a String? I would like it in the following format MM/DD/YYYY.
 
Rob Spoor
Sheriff
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Calendar.getTime() + (Simple)DateFormat is the way to go.
 
Bob Smith
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, I got it to work

String strdate = null;

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

if (calendardate != null) {
strdate = sdf.format(calendardate.getTime());
}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic