Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;

import java.util.*;

public class Main {
    public static XMLGregorianCalendar convertDate(Date date) {
        try {
            Calendar c = new GregorianCalendar();
            c.setTime(date);
            XMLGregorianCalendar xmlGregorianCalendar = DatatypeFactory.newInstance().newXMLGregorianCalendar();
            xmlGregorianCalendar.setDay(c.get(Calendar.DAY_OF_MONTH));
            xmlGregorianCalendar.setMonth(c.get(Calendar.MONTH));
            xmlGregorianCalendar.setYear(c.get(Calendar.YEAR));
            return xmlGregorianCalendar;
        } catch (DatatypeConfigurationException e) {
            throw new RuntimeException(e);
        }
    }

    public static Date convertDate(XMLGregorianCalendar date) {
        return new GregorianCalendar(date.getYear(), date.getMonth(), date.getDay()).getTime();
    }
}