Java XML Date Create xmlToDateTime(final XMLGregorianCalendar xmlCal)

Here you can find the source of xmlToDateTime(final XMLGregorianCalendar xmlCal)

Description

xml To Date Time

License

Open Source License

Declaration

public static DateTime xmlToDateTime(final XMLGregorianCalendar xmlCal) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import javax.xml.datatype.XMLGregorianCalendar;
import org.joda.time.DateTime;

public class Main {
    public static DateTime xmlToDateTime(final XMLGregorianCalendar xmlCal) {
        DateTime result = null;//from   w  w w.  jav  a 2  s  .c  om
        if (xmlCal != null) {
            int hourOfDay = xmlCal.getHour();
            int minuteOfHour = xmlCal.getMinute();
            int secondOfMinute = xmlCal.getSecond();
            int milliOfSecond = xmlCal.getMillisecond();

            if (hourOfDay < 0) {
                hourOfDay = 0;
            }
            if (minuteOfHour < 0) {
                minuteOfHour = 0;
            }
            if (secondOfMinute < 0) {
                secondOfMinute = 0;
            }
            if (milliOfSecond < 0) {
                milliOfSecond = 0;
            }
            result = new DateTime(xmlCal.getYear(), xmlCal.getMonth(), xmlCal.getDay(), hourOfDay, minuteOfHour,
                    secondOfMinute, milliOfSecond);
        }
        return result;
    }
}

Related

  1. xmlGregorianCalendarToDate(XMLGregorianCalendar calendar)
  2. XMLGregorianCalendarToDate(XMLGregorianCalendar gc)
  3. xmlGregorianCalendarToTimestamp(XMLGregorianCalendar xgc)
  4. xmlGregorianToString(XMLGregorianCalendar timestamp)
  5. xmlToDate(XMLGregorianCalendar calendar, DateFormat format)