List of usage examples for javax.xml.bind DatatypeConverter parseDateTime
public static java.util.Calendar parseDateTime(String lexicalXSDDateTime)
Converts the string argument into a Calendar value.
From source file:org.sifassociation.util.SIFAuthUtil.java
public static XMLGregorianCalendar stringToXMLGregorianCalendar(String timestamp) throws DatatypeConfigurationException { Calendar calendar = DatatypeConverter.parseDateTime(timestamp); GregorianCalendar gregorianCalendar = new GregorianCalendar(); gregorianCalendar.setTimeInMillis(calendar.getTimeInMillis()); return DatatypeFactory.newInstance().newXMLGregorianCalendar(gregorianCalendar); }
From source file:org.xcri.core.Catalog.java
@Override public void fromXml(Element element) throws InvalidElementException { super.fromXml(element); ///*from w w w . j a v a2 s . c o m*/ // Add generated // if (element.getAttribute("generated") != null) { try { Date date = new Date(); date = DatatypeConverter.parseDateTime(element.getAttributeValue("generated")).getTime(); this.setGenerated(date); // // Time and Year? // if (!element.getAttributeValue("generated").contains("T") || element.getAttributeValue("generated").split("T")[1].length() != 9) { log.warn("catalog: @generated contains date but not time:" + element.getAttributeValue("generated")); } } catch (Exception e) { log.error("catalog: @generated contains invalid date:" + element.getAttributeValue("generated")); throw new InvalidElementException( "catalog: @generated contains invalid date:" + element.getAttributeValue("generated")); } } else { this.setGenerated(new Date()); } // // Add children // ArrayList<Provider> providers = new ArrayList<Provider>(); for (Element providerElement : Lax.getChildrenQuietly(element, "provider", Namespaces.XCRI_NAMESPACE_NS, log)) { Provider provider = new Provider(); provider.fromXml(providerElement); provider.setParent(this); providers.add(provider); } this.setProviders(providers.toArray(new Provider[providers.size()])); }