Created
September 1, 2021 15:49
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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