Code example for XMLGregorianCalendar

Methods: addsetDaysetHoursetMillisecondsetMinutesetMonthsetSecondsetTimezonesetYeartoXMLFormat

0
            catch(IllegalArgumentException e) {
                System.out.println("'duration': P12Y10M1D is not 'yearMonthDuration'!!!");
            } 
             
            XMLGregorianCalendar xgc = df.newXMLGregorianCalendar();
            xgc.setYear(1975);
            xgc.setMonth(DatatypeConstants.AUGUST);
            xgc.setDay(11);
            xgc.setHour(6);
            xgc.setMinute(44);
            xgc.setSecond(0);
            xgc.setMillisecond(0);
            xgc.setTimezone(5);
            xgc.add(myPhone);
            System.out.println("The approximate end of the number of milliseconds in my phone number was " + xgc);
             
            //adding a duration to XMLGregorianCalendar 
            xgc.add(myLife);
            System.out.println("Adding the duration myLife to the above calendar:" + xgc);
             
            // create a new XMLGregorianCalendar using the string format of xgc. 
            XMLGregorianCalendar xgcCopy = df.newXMLGregorianCalendar(xgc.toXMLFormat());
             
            // should be equal-if not what happened!! 
            if (xgcCopy.compare(xgc) != DatatypeConstants.EQUAL) {
                System.out.println("oooops!");
            }