In XML Schema (XSD), all formats of dates and times are well defined.
The java.time framework built into Java 8 and later supports these formats. See Tutorial.
Here are some examples:
// Dates in XML: YYYY-MM-DD
DateTimeFormatter.ISO_LOCAL_DATE.parse("2002-09-24");
// Dates with TimeZone in XML: YYYY-MM-DDZ
DateTimeFormatter.ISO_DATE.parse("2002-09-24Z");
// Dates with TimeZone in XML: YYYY-MM-DD-06:00 or YYYY-MM-DD+06:00
DateTimeFormatter.ISO_DATE.parse("2002-09-24-06:00");
// Times in XML: hh:mm:ss
DateTimeFormatter.ISO_TIME.parse("09:00:00");
DateTimeFormatter.ISO_TIME.parse("09:00:00.5");
// DateTimes in XML: YYYY-MM-DDThh:mm:ss (with an optional TimeZone)
DateTimeFormatter.ISO_DATE_TIME.parse("2002-05-30T09:00:00");
DateTimeFormatter.ISO_DATE_TIME.parse("2002-05-30T09:30:10.5");
DateTimeFormatter.ISO_DATE_TIME.parse("2002-05-30T09:00:00Z");
DateTimeFormatter.ISO_DATE_TIME.parse("2002-05-30T09:30:10.5-06:00");
Durations and Periods however are not perfectly compatible, because they are split in Durations and Periods in Java. Here are however some examples:
Period.parse("P5Y");
Period.parse("P5Y2M10D");
Duration.parse("PT15H");
Duration.parse("-P10D");