Java Data Type How to - Create local time from hour and minute








Question

We would like to know how to create local time from hour and minute.

Answer

import java.time.LocalTime;
//from  w  ww .jav  a2  s  .c o  m
public class Main {

  public static void main(String[] args) {
    int hours = 12;
    int minutes = 30;
    LocalTime classStart = LocalTime.of(hours, minutes);

    System.out.println(classStart);
  }
}

The code above generates the following result.