List of usage examples for java.util GregorianCalendar setTime
public final void setTime(Date date)
Date
. From source file:Main.java
public static XMLGregorianCalendar convertDateToXmlDate(Date date) { try {//from ww w. java2 s.c o m GregorianCalendar fromDate = new GregorianCalendar(); fromDate.setTime(date); return DatatypeFactory.newInstance().newXMLGregorianCalendar(fromDate); } catch (DatatypeConfigurationException e) { throw new RuntimeException(e); } }
From source file:Main.java
/** * Converts a {@link Date} into a {@link XMLGregorianCalendar} * //w w w .j av a 2s. c om * @param date * the date to be converted * @return the XMLGregorianCalendar representing the date converted * @throws DatatypeConfigurationException */ public static XMLGregorianCalendar getXMLGregorianCalendarFromDate(Date date) throws DatatypeConfigurationException { XMLGregorianCalendar retObj = null; if (date != null) { GregorianCalendar gregCal = new GregorianCalendar(); gregCal.setTime(date); retObj = DatatypeFactory.newInstance().newXMLGregorianCalendar(gregCal); } return retObj; }
From source file:Main.java
public static XMLGregorianCalendar toGregorianCaldendar(final Date date) { if (date != null) { GregorianCalendar c = new GregorianCalendar(); c.setTime(date); try {//from ww w. j a v a 2 s. co m return DatatypeFactory.newInstance().newXMLGregorianCalendar(c); } catch (DatatypeConfigurationException e) { throw new RuntimeException(e); } } return null; }
From source file:Main.java
/** * Convert the {@link Date} into a {@link XMLGregorianCalendar}. * /*from www .ja v a 2 s. co m*/ * Calls {@link DatatypeFactory#newInstance()} - if a {@link DatatypeConfigurationException} * is thrown it get's wrapped in the unchecked {@link IllegalStateException}. * * @param date * @return the converted calendar * @throws IllegalStateException wrapping a {@link DatatypeConfigurationException}. */ public static XMLGregorianCalendar convertDateToXMLGregorianCalendar(final Date date) { GregorianCalendar calendar = new GregorianCalendar(); calendar.setTime(date); try { return DatatypeFactory.newInstance().newXMLGregorianCalendar(calendar); } catch (DatatypeConfigurationException e) { throw new IllegalStateException("unable to invoke DatatypeFactory.newInstance", e); } }
From source file:Main.java
/** * Reset the time of a date//from w w w . java2 s . c o m * @param date the date with time to reset * @return the 0 time date. */ public static Date zeroTimeDate(Date date) { final GregorianCalendar gregorianCalendar = new GregorianCalendar(); gregorianCalendar.setTime(date); gregorianCalendar.set(Calendar.HOUR_OF_DAY, 0); gregorianCalendar.set(Calendar.MINUTE, 0); gregorianCalendar.set(Calendar.SECOND, 0); gregorianCalendar.set(Calendar.MILLISECOND, 0); return gregorianCalendar.getTime(); }
From source file:org.eclipse.om2m.commons.utils.DateConverter.java
/** * Converts java.util.Date to javax.xml.datatype.XMLGregorianCalendar * @param date - The Date to convert/*from w w w. ja v a2 s. com*/ * @return xmlGregorianCalendar object */ public static XMLGregorianCalendar toXMLGregorianCalendar(Date date) { GregorianCalendar gregorianCalendar = new GregorianCalendar(); gregorianCalendar.setTime(date); XMLGregorianCalendar xmlGregorianCalendar = null; try { xmlGregorianCalendar = DatatypeFactory.newInstance().newXMLGregorianCalendar(gregorianCalendar); } catch (DatatypeConfigurationException e) { LOGGER.error("Date to XMLGregorianCalendar error", e); } return xmlGregorianCalendar; }
From source file:TimeUtil.java
public static String monthStringFormat(long msecs) { GregorianCalendar cal = new GregorianCalendar(); cal.setTime(new Date(msecs)); return monthStringFormat(cal.get(Calendar.MONTH)); }
From source file:Main.java
/** * Converts a java.util.Date to a javax.xml.datatype.XMLGregorianCalendar, uses current time if specified date is null; * //from w w w .j a v a2s . c o m * @param date, uses current time if specified date is null * @return a corresponding XMLGregorianCalendar object */ public static XMLGregorianCalendar convertDateToXmlDate(Date date) { try { GregorianCalendar fromDate = new GregorianCalendar(); if (date != null) { fromDate.setTime(date); } return DatatypeFactory.newInstance().newXMLGregorianCalendar(fromDate); } catch (DatatypeConfigurationException e) { throw new RuntimeException(e); } }
From source file:com.microsoft.exchange.DateHelp.java
/** * // w w w . j ava 2 s . c o m * @param date * @return */ public static XMLGregorianCalendar convertDateToXMLGregorianCalendar(final Date date) { if (date == null) { return null; } GregorianCalendar calendar = new GregorianCalendar(); calendar.setTime(date); try { return DatatypeFactory.newInstance().newXMLGregorianCalendar(calendar); } catch (DatatypeConfigurationException e) { throw new IllegalStateException("unable to invoke DatatypeFactory.newInstance", e); } }
From source file:com.microsoft.exchange.DateHelper.java
/** * Convert the {@link Date} into a {@link XMLGregorianCalendar}. * // w w w . ja v a2 s . com * @param date * @return * @throws IllegalStateException wrapping a {@link DatatypeConfigurationException}. */ public static XMLGregorianCalendar convertDateToXMLGregorianCalendar(final Date date) { if (date == null) { return null; } GregorianCalendar calendar = new GregorianCalendar(); calendar.setTime(date); return DATATYPE_FACTORY.newXMLGregorianCalendar(calendar); }