June 2018
Beginner
722 pages
18h 47m
English
The class LocalTime contains the time without a date. It has methods similar to those of the class LocalDate.
Here is how an object of the LocalTime class can be created:
System.out.println(LocalTime.now()); //prints: 21:15:46.360904ZoneId zoneId = ZoneId.of("Asia/Tokyo");System.out.println(LocalTime.now(zoneId)); //prints: 12:15:46.364378LocalTime lt1 = LocalTime.parse("20:23:12");System.out.println(lt1); //prints: 20:23:12LocalTime lt2 = LocalTime.of(20, 23, 12);System.out.println(lt2); //prints: 20:23:12
Each component of the time value can be extracted from a LocalTime object as follows:
System.out.println(lt2.getHour()); //prints: 20System.out.println(lt2.getMinute()); //prints: 23System.out.println(lt2.getSecond()) ...
Read now
Unlock full access