Java XML Date Create toXMLGregorianCalendar(long timestamp)

Here you can find the source of toXMLGregorianCalendar(long timestamp)

Description

to XML Gregorian Calendar

License

Open Source License

Declaration

public static XMLGregorianCalendar toXMLGregorianCalendar(long timestamp) 

Method Source Code

//package com.java2s;
/**// www . jav a 2 s  .c  om
 * This file is part of JEMMA - http://jemma.energy-home.org
 * (C) Copyright 2013 Telecom Italia (http://www.telecomitalia.it)
 *
 * JEMMA is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License (LGPL) version 3
 * or later as published by the Free Software Foundation, which accompanies
 * this distribution and is available at http://www.gnu.org/licenses/lgpl.html
 *
 * JEMMA 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 (LGPL) for more details.
 *
 */

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 {
    public static final TimeZone GMT_TIME_ZONE = TimeZone.getTimeZone("GMT");

    public static XMLGregorianCalendar toXMLGregorianCalendar(long timestamp) {
        GregorianCalendar gc = new GregorianCalendar(GMT_TIME_ZONE);
        gc.setTimeInMillis(timestamp);

        try {
            return DatatypeFactory.newInstance().newXMLGregorianCalendar(gc);
        } catch (DatatypeConfigurationException e) {
            e.printStackTrace();
            return null;
        }

    }
}

Related

  1. toXMLGregorianCalendar(Date date)
  2. toXMLGregorianCalendar(Date date)
  3. toXMLGregorianCalendar(Date date, TimeZone timeZone, Locale locale)
  4. toXmlGregorianCalendar(GregorianCalendar calendar)
  5. toXMLGregorianCalendar(long dateInMillis)
  6. toXMLGregorianCalendar(String stringTypeDate)
  7. toXMLGregorianCalendar(Timestamp timestamp)
  8. xmlCalendarToCalendar(XMLGregorianCalendar cal)
  9. xmlCalendarToCalendar(XMLGregorianCalendar xmlCalendar)