Java XML Date Create dateToXml(Date date)

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

Description

date To Xml

License

Open Source License

Declaration

public static XMLGregorianCalendar dateToXml(Date date) 

Method Source Code

//package com.java2s;

import java.util.Calendar;
import java.util.Date;

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

public class Main {
    public static XMLGregorianCalendar dateToXml(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);//w ww.  j  a  va2 s  .c o m
        XMLGregorianCalendar sdate = null;
        try {
            sdate = DatatypeFactory.newInstance().newXMLGregorianCalendar();
            sdate.setYear(calendar.get(Calendar.YEAR));
            sdate.setMonth(calendar.get(Calendar.MONTH) + 1);
            sdate.setDay(calendar.get(Calendar.DAY_OF_MONTH));
            sdate.setHour(calendar.get(Calendar.HOUR_OF_DAY));
            sdate.setMinute(calendar.get(Calendar.MINUTE));
            sdate.setSecond(calendar.get(Calendar.SECOND));
            sdate.setTimezone(calendar.get(Calendar.ZONE_OFFSET) / 60000);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return sdate;
    }
}

Related

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