Here you can find the source of toDateTime(Date date)
Parameter | Description |
---|---|
date | the Java date to convert |
public static XMLGregorianCalendar toDateTime(Date date)
//package com.java2s; //License from project: LGPL import java.util.*; import javax.xml.datatype.*; public class Main { private static DatatypeFactory datatypeFactory; /**//w ww . ja v a 2s. c om * Convert a Java date to its XML date/time equivalent. * * @param date the Java date to convert * @return an XML date/time */ public static XMLGregorianCalendar toDateTime(Date date) { GregorianCalendar cal = new GregorianCalendar(); cal.setTime(date); return datatypeFactory().newXMLGregorianCalendar(cal).normalize(); } /** * Convert milliseconds offset to its XML date/time equivalent. * * @param millis a millisecond count since the epoch * @return an XML date/time */ public static XMLGregorianCalendar toDateTime(long millis) { GregorianCalendar cal = new GregorianCalendar(); cal.setTimeInMillis(millis); return datatypeFactory().newXMLGregorianCalendar(cal).normalize(); } /** * Return a shared instance of a datatype factory, used for creating new XML data objects. * * @return a shared datatype factory */ public static DatatypeFactory datatypeFactory() { return datatypeFactory; } }