Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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