Skip to content

Instantly share code, notes, and snippets.

@tomwhoiscontrary
Created September 1, 2021 15:49
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 tomwhoiscontrary/6b1c17c0c2cd14eea9318c13925f38ac to your computer and use it in GitHub Desktop.
Save tomwhoiscontrary/6b1c17c0c2cd14eea9318c13925f38ac to your computer and use it in GitHub Desktop.
When do periods of the day start in Java 17? https://twitter.com/tomwhoscontrary/status/1433090964898340869
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.Locale;
public class WhenDoPeriodsStart {
public static void main(String[] args) {
Locale locale = Locale.forLanguageTag(args[0]);
System.out.println("vendor = " + System.getProperty("java.vm.vendor"));
System.out.println("version = " + System.getProperty("java.runtime.version"));
System.out.println("locale = " + locale);
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("B").withLocale(locale);
LocalTime prevTime = null;
String prevPeriod = null;
LocalTime time = LocalTime.MIDNIGHT;
while (prevTime == null || time.isAfter(prevTime)) {
String period = formatter.format(time);
if (!period.equals(prevPeriod)) {
System.out.println(time + " " + period);
}
prevTime = time;
prevPeriod = period;
time = time.plusMinutes(1);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment