问题
Before Java 8 the common method was the Calendar
API:
Calendar cal = Calendar.getInstance();
int hour = cal.get(Calendar.HOUR_OF_DAY);
How can I get the current hour, but using the new Date-Time API provided in Java 8?
回答1:
This all depends, but something like...
LocalTime now = LocalTime.now();
System.out.println(now.getHour());
Should work just fine...
Take a closer look at LocalTime#getHour for more details
来源:https://stackoverflow.com/questions/25539891/how-to-get-the-current-hour-with-new-date-time-api-in-java-8