How do I subtract two XmlGregorianCalendar objects to create one Duration object?

java

Solution

That should be:

DatatypeFactory.newDuration(xgc2.toGregorianCalendar().getTimeInMillis() - xgc1.toGregorianCalendar().getTimeInMillis())

Problem

I want to compute the delta of time, a subtraction, between two `XmlGregorianCalendar` objects, so as to create a `Duration` object. But I haven't found clean ways of performing that subtraction. How would you do it?

Original source