0

I'm trying to work out a better way of converting a date that is in the form of a gregorian calendar into an XML so later it is easy to get it back. I'm trying to avoid parsing the date out if I can avoid it.

The date is implemented in a class as

GregorianCalendar dateOfBirth;
public void setDateOfBirth(GregorianCalendar dateIn ){
    this.dateOfBirth = dateIn;
}
public GregorianCalendar getDOB(GregorianCalendar dateIn ){
    return this.dateOfBirth;
}

//To set the date of birth
newStudent.setDateOfBirth(new GregorianCalendar(dobYEAR, dobMON, dobDAY));

Currently I am sending the XML a string using

documentModel.createTextNode(thisStudent.toStringDOB());

Which sends a string

05/09/1984

This would be fine for a display but, when I read the XML back I want to store it as gregorian calendar. Im sure I can break it down to ints of month day and year then send those individually into the XML with something to the effect like this

documentModel.createTextNode(thisStudent.getDOBday().toString());
documentModel.createTextNode(thisStudent.getDOBmonth().toString());
documentModel.createTextNode(thisStudent.getDOByear().toString());

And when I parse the XML back in i could set a new gregorian date. But would like to do something simple like.

documentModel.createTextNode(thisStudent.getDOB().toString());

Where there would be only one item that needs to be delt with on both ends. But the toString method for calendar/gregorian calendar is not useful for the situation I need.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Rob McNeil
  • 51
  • 8
  • possible duplicate of [Convert a string to a GregorianCalendar](http://stackoverflow.com/questions/2331513/convert-a-string-to-a-gregoriancalendar) – Chris Stillwell Jul 24 '15 at 15:53
  • This article covers half of my question. Im looking for a simpler gregorian out/ gregorian In situation. – Rob McNeil Jul 24 '15 at 19:31

0 Answers0