title: Convert Java Gregorian Calendar to String
body: <p>I have a Book Class and one of its attributes is:</p>
  
  <pre><code>private Calendar publish_date;
  </code></pre>
  
  <p>Now I would like to insert a new Book in a library.xml file. So I create a book:</p>
  
  <pre><code>Book b = new Book();
  b.setPublish_date(new GregorianCalendar(1975, 5, 7));
  </code></pre>
  
  <p>I need that date to be a String so that I can write it in XML file (using DOM). So I perform:</p>
  
  <pre><code>    Element publish_date = doc.createElement("publish_date");
      SimpleDateFormat formatter=new SimpleDateFormat("yyyy MM DD"); 
      publish_date.appendChild(doc.createTextNode(formatter.format(b.getPublish_date())));
      book.appendChild(publish_date);
  </code></pre>
  
  <p>but this is the error:</p>
  
  <pre><code>java.lang.IllegalArgumentException: Cannot format given Object as a Date
  at java.text.DateFormat.format(DateFormat.java:301)
  at java.text.Format.format(Format.java:157)
  at fileLock.FileLock.updateLibrary(FileLock.java:127)
  at fileLock.FileLock.main(FileLock.java:63)
  </code></pre>
  
  <p>so which is the correct way to convert a Calendar (Gregorian Calendar) to a string? Thanks</p>