我如何减去两个XmlGregorianCalendar对象来创建一个Duration对象?(How do I subtract two XmlGregorianCalendar objects to create one Duration object?)

我想计算两个XmlGregorianCalendar对象之间的时间差(一种减法),以创建一个Duration对象。

但我还没有找到干净的方式来执行减法。 你会怎么做?

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?

最满意答案

这应该是:

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

That should be:

DatatypeFactory.newDuration(xgc2.toGregorianCalendar().getTimeInMillis() - xgc1.toGregorianCalendar().getTimeInMillis())我如何减去两个XmlGregorianCalendar对象来创建一个Duration对象?(How do I subtract two XmlGregorianCalendar objects to create one Duration object?)

我想计算两个XmlGregorianCalendar对象之间的时间差(一种减法),以创建一个Duration对象。

但我还没有找到干净的方式来执行减法。 你会怎么做?

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?

最满意答案

这应该是:

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

That should be:

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