import java.util.concurrent.TimeUnit;
import java.util.EnumSet;
import java.util.Collections;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.LinkedHashMap;
import java.util.Date;
public class Main {
public static void main
(String []args
) { Map<TimeUnit,Long> result = computeDiff(
);
}
public static Map
<TimeUnit,Long
> computeDiff
(Date date1,
Date date2
) { long diffInMillies = date2.getTime() - date1.getTime();
List<TimeUnit> units = new ArrayList<TimeUnit>(EnumSet.allOf(TimeUnit.class));
Map<TimeUnit,Long> result = new LinkedHashMap<TimeUnit,Long>();
long milliesRest = diffInMillies;
for ( TimeUnit unit : units ) {
long diff = unit.convert(milliesRest,TimeUnit.MILLISECONDS);
long diffInMilliesForUnit = unit.toMillis(diff);
milliesRest = milliesRest - diffInMilliesForUnit;
result.put(unit,diff);
}
return result;
}
}
CmltcG9ydCBqYXZhLnV0aWwuY29uY3VycmVudC5UaW1lVW5pdDsKaW1wb3J0IGphdmEudXRpbC5FbnVtU2V0OwppbXBvcnQgamF2YS51dGlsLkNvbGxlY3Rpb25zOwppbXBvcnQgamF2YS51dGlsLkFycmF5TGlzdDsKaW1wb3J0IGphdmEudXRpbC5MaXN0OwppbXBvcnQgamF2YS51dGlsLk1hcDsKaW1wb3J0IGphdmEudXRpbC5MaW5rZWRIYXNoTWFwOwppbXBvcnQgamF2YS51dGlsLkRhdGU7CgpwdWJsaWMgY2xhc3MgTWFpbiB7CgogICAgIHB1YmxpYyBzdGF0aWMgdm9pZCBtYWluKFN0cmluZyBbXWFyZ3MpIHsKICAgICAJTWFwPFRpbWVVbml0LExvbmc+IHJlc3VsdCA9IGNvbXB1dGVEaWZmKAogICAgIAkJbmV3IERhdGUoU3lzdGVtLmN1cnJlbnRUaW1lTWlsbGlzKCktMTAwMDAwMDAwKSwKICAgICAJCW5ldyBEYXRlKCkKICAgICAJKTsKICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4ocmVzdWx0KTsKICAgICB9CiAgICAgCiAgICBwdWJsaWMgc3RhdGljIE1hcD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