Java tutorial
//package com.java2s; /* * Copyright 2017 Marcus Portmann * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import javax.xml.datatype.DatatypeFactory; import javax.xml.datatype.XMLGregorianCalendar; import java.util.GregorianCalendar; public class Main { /** * The <code>DatatypeFactory</code> instance used to convert java.xml.datatype object that map * XML to/from Java objects. */ private static DatatypeFactory datatypeFactory = null; /** * Converts a <code>java.util.Date</code> instance to a * <code>javax.xml.datatype.XMLGregorianCalendar</code> instance. * * @param date the <code>java.util.Date</code> instance to convert * * @return the converted <code>javax.xml.datatype.XMLGregorianCalendar</code> instance */ public static XMLGregorianCalendar asXMLGregorianCalendar(java.util.Date date) { if (date == null) { return null; } else { GregorianCalendar calendar = new GregorianCalendar(); calendar.setTimeInMillis(date.getTime()); return datatypeFactory.newXMLGregorianCalendar(calendar); } } }