Skip to content

Instantly share code, notes, and snippets.

@alexspurling
Created March 17, 2023 15:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexspurling/8770e32e28aefbcd271f09ed50d30fb3 to your computer and use it in GitHub Desktop.
Save alexspurling/8770e32e28aefbcd271f09ed50d30fb3 to your computer and use it in GitHub Desktop.
When did Michael Jackson's hair catch on fire?
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit;
/*
output:
Earliest midpoint in LA: 1984-01-26T17:13-08:00[America/Los_Angeles]
Latest midpoint in LA: 1984-01-27T05:13-08:00[America/Los_Angeles]
*/
public class MJTimes {
private static final ZoneId LA = ZoneId.of("America/Los_Angeles");
private static final ZoneId GARY = ZoneId.of("America/Chicago");
public static void main(String[] args) {
ZonedDateTime death = ZonedDateTime.of(2009, 6, 25, 14, 26, 0, 0, LA);
ZonedDateTime earliestBirth = ZonedDateTime.of(1958, 8, 29, 0, 0, 0, 0, GARY);
ZonedDateTime latestBirth = ZonedDateTime.of(1958, 8, 30, 0, 0, 0, 0, GARY);
long secondsToEarliestMidpoint = ChronoUnit.SECONDS.between(earliestBirth, death) / 2;
long secondsToLatestMidpoint = ChronoUnit.SECONDS.between(latestBirth, death) / 2;
ZonedDateTime earliestIndianaMidpoint = earliestBirth.plusSeconds(secondsToEarliestMidpoint);
ZonedDateTime latestIndianaMidpoint = latestBirth.plusSeconds(secondsToLatestMidpoint);
ZonedDateTime earliestMidpointInLa = earliestIndianaMidpoint.withZoneSameInstant(LA);
ZonedDateTime latestMidpointInLa = latestIndianaMidpoint.withZoneSameInstant(LA);
System.out.println("Earliest midpoint in LA: " + earliestMidpointInLa);
System.out.println("Latest midpoint in LA: " + latestMidpointInLa);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment