Java tutorial
//package com.java2s; import java.util.Date; import java.util.GregorianCalendar; import java.util.TimeZone; import javax.xml.datatype.DatatypeFactory; import javax.xml.datatype.XMLGregorianCalendar; public class Main { private static DatatypeFactory newInstance; public static XMLGregorianCalendar toXMLGregorianCalendarByTimeZone(Date date, TimeZone timeZone) { if (date == null) return null; GregorianCalendar calendar = new GregorianCalendar(timeZone); calendar.setTime(date); return newInstance.newXMLGregorianCalendar(calendar); } }