Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.util.Calendar;
import java.util.GregorianCalendar;

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

public class Main {
    private static DatatypeFactory df = null;

    public static XMLGregorianCalendar asXMLGregorianCalendar(java.util.Date date) {
        if (date == null) {
            return null;
        } else {
            GregorianCalendar calendar = new GregorianCalendar();
            calendar.setTime(date);

            XMLGregorianCalendar xmlGregorianCalendar = df.newXMLGregorianCalendar();
            xmlGregorianCalendar.setDay(calendar.get(Calendar.DAY_OF_MONTH));
            xmlGregorianCalendar.setMonth(calendar.get(Calendar.MONTH));
            xmlGregorianCalendar.setYear(calendar.get(Calendar.YEAR));

            return xmlGregorianCalendar;
        }
    }
}