package com.jijo;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;
import java.util.Calendar;
public class DateUtil{
public static XMLGregorianCalendar toXMLCalendar(Calendar calandar ){
XMLGregorianCalendar xmlCalendar = null;
try {
DatatypeFactory dtf = DatatypeFactory.newInstance();
xmlCalendar = dtf.newXMLGregorianCalendar();
xmlCalendar.setYear(calandar.get(Calendar.YEAR));
xmlCalendar.setDay(calandar.get(Calendar.DAY_OF_MONTH));
xmlCalendar.setMonth(calandar.get(Calendar.MONTH)+ 1);
xmlCalendar.setHour(calandar.get(Calendar.HOUR_OF_DAY));
xmlCalendar.setMinute(calandar.get(Calendar. MINUTE));
xmlCalendar.setSecond(calandar.get(Calendar. SECOND));
xmlCalendar.setMillisecond(calandar.get(Calendar.MILLISECOND));
int offsetInMinutes = (calandar.get(Calendar.ZONE_OFFSET) + calandar.get(Calendar.DST_OFFSET)) / (60 * 1000);
xmlCalendar.setTimezone(offsetInMinutes);
}
catch (Exception e) {
e.printStackTrace();
}
return xmlCalendar;
}
public static Calendar toCalendar(XMLGregorianCalendar xmlCalendar ){
return xmlCalendar.toGregorianCalendar();
}
}
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;
import java.util.Calendar;
public class DateUtil{
public static XMLGregorianCalendar toXMLCalendar(Calendar calandar ){
XMLGregorianCalendar xmlCalendar = null;
try {
DatatypeFactory dtf = DatatypeFactory.newInstance();
xmlCalendar = dtf.newXMLGregorianCalendar();
xmlCalendar.setYear(calandar.get(Calendar.YEAR));
xmlCalendar.setDay(calandar.get(Calendar.DAY_OF_MONTH));
xmlCalendar.setMonth(calandar.get(Calendar.MONTH)+ 1);
xmlCalendar.setHour(calandar.get(Calendar.HOUR_OF_DAY));
xmlCalendar.setMinute(calandar.get(Calendar. MINUTE));
xmlCalendar.setSecond(calandar.get(Calendar. SECOND));
xmlCalendar.setMillisecond(calandar.get(Calendar.MILLISECOND));
int offsetInMinutes = (calandar.get(Calendar.ZONE_OFFSET) + calandar.get(Calendar.DST_OFFSET)) / (60 * 1000);
xmlCalendar.setTimezone(offsetInMinutes);
}
catch (Exception e) {
e.printStackTrace();
}
return xmlCalendar;
}
public static Calendar toCalendar(XMLGregorianCalendar xmlCalendar ){
return xmlCalendar.toGregorianCalendar();
}
}