java.time
I recommend that you use java.time, the modern Java date and time API, for your date and time work.
ZoneId zone = ZoneId.of("America/Boise");
ZonedDateTime zdt1 = ZonedDateTime.of(2020, 12, 26, 22, 0, 0, 0, zone);
ZonedDateTime zdt2 = ZonedDateTime.of(2020, 12, 27, 1, 0, 0, 0, zone);
Duration fullElapsedTime = Duration.between(zdt1, zdt2);
Duration twoThirds = fullElapsedTime.multipliedBy(2).dividedBy(3);
ZonedDateTime lastThird = zdt1.plus(twoThirds);
System.out.println(lastThird);
Output from this snippet is:
2020-12-27T00:00-07:00[America/Boise]
Three things I like about this code are:
- It pretty well mimics the way one would do the calculation by hand and how you would explain to someone else which calculation you want at all.
- It takes any transistion to or from summer time (DST) into account.
- It leaves the actual calculation to the library methods. It involves no low-level addition or division in your own code.
Link
Oracle tutorial: Date Time explaining how to use java.time.
Date. That class is poorly designed and long outdated. Instead you probably want to use eitherLocalTimeorZonedDateTime. Both are from java.time, the modern Java date and time API.