Java tutorial
//package com.java2s; //License from project: Apache License import com.google.common.base.Function; import com.sun.org.apache.xerces.internal.jaxp.datatype.XMLGregorianCalendarImpl; import javax.xml.datatype.XMLGregorianCalendar; import java.util.Date; import java.util.GregorianCalendar; import java.util.TimeZone; public class Main { public static XMLGregorianCalendar now() { return fromDate().apply(new Date()); } public static Function<Date, XMLGregorianCalendar> fromDate() { return new Function<Date, XMLGregorianCalendar>() { @Override public XMLGregorianCalendar apply(final Date date) { if (date == null) return null; return new XMLGregorianCalendarImpl(new GregorianCalendar(TimeZone.getDefault()) { { setTime(date); } }); } }; } }