Java XML Date Create getXMLDateTime(Date date)

Here you can find the source of getXMLDateTime(Date date)

Description

A new method, that contains the code previously present in the above method, that is, to create an XML GC Object with both the Date and time component.

License

Open Source License

Declaration

public static XMLGregorianCalendar getXMLDateTime(Date date) throws DatatypeConfigurationException 

Method Source Code


//package com.java2s;
/*/*from   w w w  .jav  a 2  s. co  m*/
 * Copyright (c) 2014 Mastek Ltd. All rights reserved.
 * 
 * This file is part of JBEAM. JBEAM is free software: you can
 * redistribute it and/or modify it under the terms of the GNU Lesser
 * General Public License as published by the Free Software Foundation.
 *
 * JBEAM is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
 * Public License for the specific language governing permissions and 
 * limitations.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with JBEAM. If not, see <http://www.gnu.org/licenses/>.
 */

import java.util.Date;
import java.util.GregorianCalendar;
import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;

public class Main {
    /**
     * A new method, that contains the code previously present in the above
     * method, that is, to create an XML GC Object with both the Date and time
     * component.
     */
    public static XMLGregorianCalendar getXMLDateTime(Date date) throws DatatypeConfigurationException {
        GregorianCalendar gCal = new GregorianCalendar();
        if (date != null) {
            gCal.setTime(date);
            XMLGregorianCalendar xgCal = DatatypeFactory.newInstance().newXMLGregorianCalendar(gCal);
            return xgCal;
        } else {
            return null;
        }
    }
}

Related

  1. getXMLDate(Date date)
  2. getXMLDate(Date dateTime)
  3. getXMLDate(final Calendar calendar)
  4. getXMLDateString()
  5. getXMLDateStringFromDouble(double d)
  6. getXMLFormat(Calendar calendar)
  7. getXmlGregCal(Date dt)
  8. getXMLGregorianCalendar()
  9. getXMLGregorianCalendar(Date date)