Java XML Date Create DateToXmlCalendar(Date date)

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

Description

Date To Xml Calendar

License

Open Source License

Parameter

Parameter Description
date a parameter

Declaration

public static XMLGregorianCalendar DateToXmlCalendar(Date date) 

Method Source Code

//package com.java2s;
/**//from ww w .  j av  a2s. com
 *  This code is part of the Harmony System implemented in Work Package 1 
 *  of the Phosphorus project. This work is supported by the European 
 *  Comission under the Sixth Framework Programme with contract number 
 *  IST-034115.
 *
 *  Copyright (C) 2006-2009 Phosphorus WP1 partners. Phosphorus Consortium.
 *  http://ist-phosphorus.eu/
 *
 * This 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; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software 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 more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */

import java.util.Date;
import java.util.GregorianCalendar;

import java.util.TimeZone;
import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;

public class Main {
    private static TimeZone defaultTimeZone = null;

    /**
     * @param date
     */
    public static XMLGregorianCalendar DateToXmlCalendar(Date date) {
        GregorianCalendar calendar;
        calendar = new GregorianCalendar(getDefaultTimeZone());
        calendar.setTime(date);

        try {
            DatatypeFactory factory = DatatypeFactory.newInstance();
            return factory.newXMLGregorianCalendar(calendar);
        } catch (DatatypeConfigurationException e) {
            return null;
        }

    }

    protected static TimeZone getDefaultTimeZone() {
        if (defaultTimeZone == null) {
            defaultTimeZone = TimeZone.getDefault();
        }
        return defaultTimeZone;
    }
}

Related

  1. createXmlGregorianCalendar(Date date)
  2. createXMLGregorianCalendar(final Date date)
  3. createXMLGregorianCalendar(final Date time)
  4. dateToString(Calendar calendar)
  5. dateToXml(Date date)
  6. dateToXmlDate(Date date)
  7. dateToXMLGC(Date fecha)
  8. dateToXmlGregorian(Date timestamp)
  9. dateToXmlGregorianCalendar(Calendar date)