List of usage examples for java.util GregorianCalendar setTime
public final void setTime(Date date)
Date
. From source file:edu.utah.further.core.util.jaxb.JaxbConversionUtil.java
/** * @param s/*from ww w . j av a2 s . co m*/ * @param dateFormat * @return */ public static XMLGregorianCalendar parseDateGregorian(final String s, final SimpleDateFormat dateFormat) { try { final Date date = dateFormat.parse(s); final GregorianCalendar calendar = new GregorianCalendar(); calendar.setTime(date); return DATATYPE_FACTORY.newXMLGregorianCalendar(calendar); } catch (final ParseException e) { throw new ApplicationException("Bad date field " + s, e); } }
From source file:com.stgmastek.core.util.CommonUtils.java
/** * A new method, that contains the code previously present in the above * method, that is, to create an XML GC Object with both the Date and time * component./*from w ww . jav a2s. com*/ */ public static XMLGregorianCalendar getXMLDateTime(Date date) throws DatatypeConfigurationException { GregorianCalendar gCal = new GregorianCalendar(); if (date != null) { gCal.setTime(date); XMLGregorianCalendar xgCal = DatatypeFactory.newInstance().newXMLGregorianCalendar(gCal); return xgCal; } else { return null; } }
From source file:com.rogers.ute.creditservice.util.CreditServiceUtils.java
public static XMLGregorianCalendar asXMLGregorianCalendar(Date date) { try {/* w w w . j a v a 2s. c o m*/ GregorianCalendar instance = new GregorianCalendar(); instance.setTime(date); return DatatypeFactory.newInstance().newXMLGregorianCalendar(instance); } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:com.labs64.utils.swid.support.JAXBUtils.java
/** * Convert {@link Date} to {@link XMLGregorianCalendar}. * /*from ww w . j av a 2s .c o m*/ * @param date * XML entity */ public static XMLGregorianCalendar convertDateToXMLGregorianCalendar(final Date date) { try { GregorianCalendar cal = new GregorianCalendar(); cal.setTime(date); XMLGregorianCalendar calXml = DatatypeFactory.newInstance().newXMLGregorianCalendar( cal.get(Calendar.YEAR), cal.get(Calendar.MONTH) + 1, cal.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE), cal.get(Calendar.SECOND), cal.get(Calendar.MILLISECOND), 0); return calXml; } catch (DatatypeConfigurationException e) { throw new SwidException("Cannot convert date", e); } }
From source file:TimeUtil.java
/** * convert time in milliseconds into a display string of the form [h]h:mm * [am|pm] (traditional) or hh:mm (24 hour format) if using traditional * format, the leading 'h' & 'm' will be padded with a space to ensure * constant length if less than 10 24 hour format * //from w w w . ja v a 2 s.c om * @param msecs * a millisecond time * @return TimeString the formatted time string */ public static String stringFormat(long msecs) { GregorianCalendar cal = new GregorianCalendar(); StringBuffer sBuf = new StringBuffer(8); cal.setTime(new Date(msecs)); int hour = cal.get(Calendar.HOUR); if (hour == 0) hour = 12; if (hour < 10) sBuf.append(" "); sBuf.append(Integer.toString(hour)); sBuf.append(":"); int minute = cal.get(Calendar.MINUTE); if (minute < 10) sBuf.append("0"); sBuf.append(Integer.toString(minute)); sBuf.append(" "); sBuf.append(cal.get(Calendar.AM_PM) == Calendar.AM ? "AM" : "PM"); return (sBuf.toString()); }
From source file:net.orpiske.dcd.dispatcher.impl.WebServicesConversor.java
private static XMLGregorianCalendar newXmlGregorianCalendar(final Date date) { GregorianCalendar reportDate = new GregorianCalendar(); reportDate.setTime(date); XMLGregorianCalendar ret = null; try {/*from w w w.ja v a 2s . co m*/ ret = DatatypeFactory.newInstance().newXMLGregorianCalendar(reportDate); } catch (DatatypeConfigurationException e) { logger.error("Unable to properly transform a date for XML data transfer: " + e.getMessage(), e); } return ret; }
From source file:TimeUtil.java
public static String stringSecsFormat(long msecs) { GregorianCalendar cal = new GregorianCalendar(); StringBuffer sBuf = new StringBuffer(11); cal.setTime(new Date(msecs)); int hour = cal.get(Calendar.HOUR); if (hour == 0) hour = 12;// w w w.j av a 2 s . com if (hour < 10) sBuf.append(" "); sBuf.append(Integer.toString(hour)); sBuf.append(":"); int minute = cal.get(Calendar.MINUTE); if (minute < 10) sBuf.append("0"); sBuf.append(Integer.toString(minute)); sBuf.append(":"); int secs = cal.get(Calendar.SECOND); if (secs < 10) { sBuf.append("0"); } sBuf.append(Integer.toString(secs)); sBuf.append(" "); sBuf.append(cal.get(Calendar.AM_PM) == Calendar.AM ? "AM" : "PM"); return (sBuf.toString()); }
From source file:au.com.jwatmuff.eventmanager.model.misc.PoolChecker.java
public static int calculateAge(Date dob, Date censusDate) { if (dob == null) return -1; /* calculate age */ GregorianCalendar birthCal = new GregorianCalendar(); birthCal.setTime(dob); int birthYear = birthCal.get(GregorianCalendar.YEAR); GregorianCalendar censusCal = new GregorianCalendar(); censusCal.setTime(censusDate);// w w w .ja v a 2 s. c om int censusYear = censusCal.get(GregorianCalendar.YEAR); int age = censusYear - birthYear; birthCal.set(GregorianCalendar.YEAR, censusYear); if (censusCal.before(birthCal)) { age--; } return age; }
From source file:edu.cornell.mannlib.semservices.util.DateConverter.java
public static XMLGregorianCalendar toXMLGregorianCalendar(Date date) { try {//from w w w. ja v a 2 s . co m GregorianCalendar calendar = new GregorianCalendar(); calendar.setTime(date); return DatatypeFactory.newInstance().newXMLGregorianCalendar(calendar); } catch (DatatypeConfigurationException e) { return null; } }
From source file:org.jrecruiter.common.CalendarUtils.java
/** * Get a XML-date representation (ISO 8601) of the provided calendar object. * * For more details @see http://www.w3.org/TR/xmlschema-2/#dateTime * * @return XML-date as String//from ww w. jav a 2s. co m */ public static String getXmlFormatedDate(final Calendar calendar) { if (calendar == null) { throw new IllegalArgumentException("Calendar is a required parameter"); } final GregorianCalendar gregorianCalendar = new GregorianCalendar(calendar.getTimeZone()); gregorianCalendar.setTime(calendar.getTime()); final DatatypeFactory dataTypeFactory; try { dataTypeFactory = DatatypeFactory.newInstance(); } catch (DatatypeConfigurationException e) { throw new IllegalStateException(e.getMessage(), e); } final XMLGregorianCalendar xmlCalendar = dataTypeFactory.newXMLGregorianCalendar(gregorianCalendar); return xmlCalendar.toXMLFormat(); }