Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Found it myself.</p> <pre><code> try { DatatypeFactory dtFactory = DatatypeFactory.newInstance(); } catch (DatatypeConfigurationException e) { // TODO Auto-generated catch block e.printStackTrace(); } Duration duration = dtFactory.newDuration("p0dt1h0m0s"); </code></pre> <p>Edit..</p> <p>The above is not possible due to a DatatypeFactory bug sooo i built this class to fix it myself..</p> <pre><code>public class XmlDuration { private String _xmlDuration; private int _years; private int _months; private int _days; private int _hours; private int _minutes; private int _seconds; private boolean _isNegative; public XmlDuration(String xmlDuration) { try { _xmlDuration = xmlDuration; _isNegative = ((String)_xmlDuration.subSequence(0,1)).matches("[-]"); String period; String time; int tIndex =_xmlDuration.indexOf("T"); period = xmlDuration.substring(0, tIndex); time = _xmlDuration.substring(tIndex); String numericSection = ""; for (int i = 0; i &lt; period.length(); i++) { char[] c = new char[] {period.charAt(i)}; String s = new String(c); if(s.matches("\\d")) { numericSection += s; } else if (s.matches("[Yy]")) { _years = Integer.parseInt(numericSection); numericSection = ""; } else if (s.matches("[Mm]")) { _months = Integer.parseInt(numericSection); numericSection = ""; } else if (s.matches("[Dd]")) { _days = Integer.parseInt(numericSection); numericSection = ""; } } for (int i = 0; i &lt; time.length(); i++) { char[] c = new char[] {time.charAt(i)}; String s = new String(c); if(s.matches("\\d")) { numericSection += s; } else if (s.matches("[Hh]")) { _hours = Integer.parseInt(numericSection); numericSection = ""; } else if (s.matches("[Mm]")) { _minutes = Integer.parseInt(numericSection); numericSection = ""; } else if (s.matches("[Ss]")) { _seconds = Integer.parseInt(numericSection); numericSection = ""; } } } catch (Exception e) { // TODO: handle exception } } public String getXmlString() { return _xmlDuration; } public int getYears() { return _years; } public int getMonth() { return _months; } public int getDays() { return _days; } public int getHours() { return _hours; } public int getMinutes() { return _minutes; } public int getSeconds() { return _seconds; } public boolean getIsNegative() { return _isNegative; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload