Returns a Duration with the difference between this
and other
.
DateTime berlinWallFell = new DateTime.utc(1989, DateTime.NOVEMBER, 9);
DateTime dDay = new DateTime.utc(1944, DateTime.JUNE, 6);
Duration difference = berlinWallFell.difference(dDay);
assert(difference.inDays == 16592);
The difference is measured in seconds and fractions of seconds. The difference above counts the number of fractional seconds between midnight at the beginning of those dates. If the dates above had been in local time, not UTC, then the difference between two midnights may not be a multiple of 24 hours due to daylight saving differences.
For example, in Australia, similar code using local time instead of UTC:
DateTime berlinWallFell = new DateTime(1989, DateTime.NOVEMBER, 9);
DateTime dDay = new DateTime(1944, DateTime.JUNE, 6);
Duration difference = berlinWallFell.difference(dDay);
assert(difference.inDays == 16592);
will fail because the difference is actually 16591 days and 23 hours, and Duration.inDays only returns the number of whole days.
Source
external Duration difference(DateTime other);