How can I subtract these two dates?
You can get the difference in milliseconds as follows:
dtEndDate.getTime() - dtStartDate.getTime()
( getTime returns the number of milliseconds since January 1, 1970, 00:00:00 GMT.)
However, for this type of date arithmetic, the Joda time library , which has the appropriate classes for Duration , is probably the best option.
source share