List of usage examples for javax.xml.datatype DatatypeFactory newInstance
public static DatatypeFactory newInstance() throws DatatypeConfigurationException
From source file:Main.java
public static GregorianCalendar fromXSDateTime(String dateTime) throws DatatypeConfigurationException { GregorianCalendar cal = null; if (dateTime != null && dateTime.length() != 0) { cal = DatatypeFactory.newInstance().newXMLGregorianCalendar(dateTime).toGregorianCalendar(); cal.setTimeZone(TimeZone.getTimeZone("UTC")); }/*from ww w. ja va2 s .c om*/ return cal; }
From source file:Main.java
public static XMLGregorianCalendar xmlGregorianCalendar() throws DatatypeConfigurationException { GregorianCalendar cal = new GregorianCalendar(); return DatatypeFactory.newInstance().newXMLGregorianCalendar(cal); }
From source file:Main.java
public static XMLGregorianCalendar getXmlGregorianCalendarFromDate(Date date) { GregorianCalendar cal = new GregorianCalendar(); cal.setTime(date);/*from w w w. j a v a 2 s . c om*/ XMLGregorianCalendar f = null; try { f = DatatypeFactory.newInstance().newXMLGregorianCalendar(cal); } catch (DatatypeConfigurationException e) { e.printStackTrace(); } return f; }
From source file:Main.java
public static XMLGregorianCalendar parse(String time) { XMLGregorianCalendar date = null; try {/*w w w . j ava 2 s. c o m*/ if (time.indexOf(":") < 0) { time = time + "T00:00:00"; } date = DatatypeFactory.newInstance().newXMLGregorianCalendar(time); } catch (DatatypeConfigurationException e) { e.printStackTrace(); } return date; }
From source file:Main.java
/** * Parse an XML Date Time into an XMLGregorianCalendar. * * @param toParse// w w w . jav a2 s .co m * the xml date time string to parse. * @return the parsed XMLGregorianCalendar object. */ public static XMLGregorianCalendar getXMLGregorianCalendar(final String toParse) { try { return DatatypeFactory.newInstance().newXMLGregorianCalendar(toParse); } catch (Exception e) { return null; } }
From source file:Main.java
public static XMLGregorianCalendar dateToXmlCalendar(Date date) { if (date != null) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date);/*from w w w . j av a 2s. co m*/ try { XMLGregorianCalendar xmlGregorianCalendar = DatatypeFactory.newInstance().newXMLGregorianCalendar(); xmlGregorianCalendar.setDay(calendar.get(Calendar.DAY_OF_MONTH)); xmlGregorianCalendar.setMonth(calendar.get(Calendar.MONTH) + 1); xmlGregorianCalendar.setYear(calendar.get(Calendar.YEAR)); return xmlGregorianCalendar; } catch (DatatypeConfigurationException e) { return null; } } return null; }
From source file:Main.java
public static XMLGregorianCalendar longToXMLGregorianCalendar(long time) throws DatatypeConfigurationException { if (time <= 0) { return null; }// ww w.j a va2s .c o m GregorianCalendar cal = new GregorianCalendar(); cal.setTimeInMillis(time); XMLGregorianCalendar newXMLGregorianCalendar = DatatypeFactory.newInstance().newXMLGregorianCalendar(cal); return newXMLGregorianCalendar; }
From source file:Main.java
/** * date -> XMLGregorianCalendar//w w w . java2 s . co m * * @param date * @return XMLGregorianCalendar * @throws DatatypeConfigurationException */ @SuppressWarnings("static-access") public static XMLGregorianCalendar getXMLGregorianCalendar(java.util.Date date) throws DatatypeConfigurationException { Calendar calendar = Calendar.getInstance(); calendar.setTime(date); DatatypeFactory dtf = DatatypeFactory.newInstance(); return dtf.newXMLGregorianCalendar(calendar.get(calendar.YEAR), calendar.get(calendar.MONTH) + 1, calendar.get(calendar.DAY_OF_MONTH), calendar.get(calendar.HOUR), calendar.get(calendar.MINUTE), calendar.get(calendar.SECOND), calendar.get(calendar.MILLISECOND), calendar.get(calendar.ZONE_OFFSET) / (1000 * 60)); }
From source file:Main.java
/** * Parse an xs:dateTime value in "2009-05-21T14:52:18-07:00" format (with the timezone). * /*from w w w . j a v a2 s . com*/ * @param timestamp * The xs:dateTime * @return The converted date * @throws DatatypeConfigurationException * For errors. */ public static Date parseXmlDateTimeWithZone(String timestamp) throws DatatypeConfigurationException { DatatypeFactory datatypeFactory = DatatypeFactory.newInstance(); XMLGregorianCalendar xmlGregorianCalendar = datatypeFactory.newXMLGregorianCalendar(timestamp); GregorianCalendar gregorianCalendar = xmlGregorianCalendar.toGregorianCalendar(); return gregorianCalendar.getTime(); }
From source file:Main.java
public static XMLGregorianCalendar xmlGregorianCalendar(Date date) throws DatatypeConfigurationException { GregorianCalendar cal = new GregorianCalendar(); cal.setTime(date);/*w w w.j a v a 2 s.c om*/ return DatatypeFactory.newInstance().newXMLGregorianCalendar(cal); }