Calendar
object.
*/
public static Calendar toCalendar(final Date date) {
final Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
return calendar;
}
/**
* Creates an instance of {@link java.util.Calendar} from the given time in milliseconds.
*
* The input milliseconds value represents the specified number of milliseconds since the standard base time known
* as "the epoch", namely January 1, 1970, 00:00:00 GMT.
*
* @param millis
* A given time corresponding to the number of milliseconds since January 1, 1970, 00:00:00 GMT
* @return Converted Calendar
object.
*/
public static Calendar toCalendar(final long millis) {
final Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(millis);
return calendar;
}
/**
* Converts a given time as an instance of {@link java.util.Date} into a {@link XMLGregorianCalendar} object.
*
* @param date
* A given time as an instance of java.util.Date
* @return A new instance of XMLGregorianCalendar
representing the input time
*/
public static XMLGregorianCalendar toXmlGregorianCalendar(final Date date) {
return toXmlGregorianCalendar(date.getTime());
}
/**
* Converts a given time in milliseconds into a {@link XMLGregorianCalendar} object.
*
* The input milliseconds value represents the specified number of milliseconds since the standard base time known
* as "the epoch", namely January 1, 1970, 00:00:00 GMT.
*
* @param date
* A given time corresponding to the number of milliseconds since January 1, 1970, 00:00:00 GMT
* @return A new instance of XMLGregorianCalendar
representing the input time
*/
public static XMLGregorianCalendar toXmlGregorianCalendar(final long date) {
try {
final GregorianCalendar calendar = new GregorianCalendar();
calendar.setTimeInMillis(date);
return DatatypeFactory.newInstance().newXMLGregorianCalendar(
calendar);
}
catch (final DatatypeConfigurationException ex) {
System.out.println("Unable to convert date '%s' to an XMLGregorianCalendar object");
}
}
}