List of usage examples for javax.xml.datatype DatatypeFactory newInstance
public static DatatypeFactory newInstance() throws DatatypeConfigurationException
From source file:Main.java
/** * Format a date in xs:dateTime format./*from www . jav a2 s . com*/ * * @param date * The date. * @return The xs:dateTime * @throws DatatypeConfigurationException * For errors. */ public static String formatXmlDateTimeWithZone(Date date) throws DatatypeConfigurationException { GregorianCalendar gc = new GregorianCalendar(); gc.setTime(date); DatatypeFactory datatypeFactory = DatatypeFactory.newInstance(); XMLGregorianCalendar xmlGregorianCalendar = datatypeFactory.newXMLGregorianCalendar(gc); return xmlGregorianCalendar.toXMLFormat(); }
From source file:Main.java
public static XMLGregorianCalendar toXmlDate(Date date) { try {/*from w w w . j a v a2 s . c om*/ GregorianCalendar c = new GregorianCalendar(); c.setTime(date); return DatatypeFactory.newInstance().newXMLGregorianCalendar(c); } catch (DatatypeConfigurationException dtce) { throw new UnsupportedOperationException("Nemohu prevest " + "GregorianCalendar na XMLGregorianCalendar", dtce); } }
From source file:Main.java
/** * Converts a {@link Date} into a {@link XMLGregorianCalendar} * //from w w w . j a va 2s. co m * @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 parse(String time, int timezone) { XMLGregorianCalendar date = null; try {/*from ww w.j a v a 2s . co m*/ if (time.indexOf(":") < 0) { time = time + "T00:00:00"; } date = DatatypeFactory.newInstance().newXMLGregorianCalendar(time); date.setTimezone(timezone); } catch (DatatypeConfigurationException e) { e.printStackTrace(); } return date; }
From source file:Main.java
public static String DateToXSD_DateTime(Date d) { DatatypeFactory f;/* www .ja v a 2 s. co m*/ try { f = DatatypeFactory.newInstance(); } catch (DatatypeConfigurationException e) { throw new RuntimeException(e); } GregorianCalendar cal = new GregorianCalendar(); cal.setTime(d); return f.newXMLGregorianCalendar(cal).toXMLFormat(); }
From source file:Main.java
/** * Format a Gregorian Calendar as an XML DateTime String. * * @param calendar//from w w w. j av a2s.c o m * the calendar to format. * @return the XML representation as a string. */ public static String formatGregorianCalendar(final GregorianCalendar calendar) { try { return DatatypeFactory.newInstance().newXMLGregorianCalendar(calendar).normalize().toXMLFormat(); } catch (Exception e) { return null; } }
From source file:Main.java
public static Date XSD_DateTime_ToDate(String datetime) throws ParseException { DatatypeFactory f;//from ww w.j a v a 2 s. c om try { f = DatatypeFactory.newInstance(); } catch (DatatypeConfigurationException e) { throw new RuntimeException(e); } return f.newXMLGregorianCalendar(datetime).toGregorianCalendar().getTime(); }
From source file:Main.java
public static XMLGregorianCalendar timestampToXMLGregorianCalendar(Timestamp t) { if (t == null) { return null; }/* w ww . jav a 2 s .co m*/ GregorianCalendar gc = new GregorianCalendar(); gc.setTimeInMillis(t.getTime()); try { return DatatypeFactory.newInstance().newXMLGregorianCalendar(gc); } catch (DatatypeConfigurationException ex) { return null; } }
From source file:Main.java
/** * Gets the XML Gregorian calendar from date. * * @param date the date./*from w w w . jav a2 s.c om*/ * * @return the XML Gregorian calendar. */ public static XMLGregorianCalendar getXMLDate(Date date) { DatatypeFactory dataTypeFactory; try { dataTypeFactory = DatatypeFactory.newInstance(); } catch (DatatypeConfigurationException e) { throw new RuntimeException(e); } GregorianCalendar gc = new GregorianCalendar(); gc.setTimeInMillis(date.getTime()); return dataTypeFactory.newXMLGregorianCalendar(gc); }
From source file:Main.java
public static XMLGregorianCalendar long2XMLGregorian(long dateAsLong) { DatatypeFactory dataTypeFactory; try {// ww w . ja v a 2 s . c o m dataTypeFactory = DatatypeFactory.newInstance(); } catch (DatatypeConfigurationException e) { throw new RuntimeException(e); } GregorianCalendar gc = new GregorianCalendar(); gc.setTimeInMillis(dateAsLong); return dataTypeFactory.newXMLGregorianCalendar(gc); }