Si entiendo bien su pregunta:
import java.util.*;
import java.lang.*;
import java.io.*;
import java.time.LocalTime;
/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
int h;
int m;
int s;
Scanner scanner = new Scanner(System.in);
System.out.println("introduzca la hora");
h = scanner.nextInt();
System.out.println("introduzca los minutos");
m = scanner.nextInt();
System.out.println("introduzca los segundos");
s = scanner.nextInt();
LocalTime lcl = LocalTime.of(h, m, s);
//System.out.println(h +" "+ m +" "+ s);
System.out.println(lcl.getHour());
System.out.println(lcl.getMinute());
System.out.println(lcl.getSecond());
}
}
...que mediante Scanner pueda asignarles la hora que desee...
//variables para alamcenar los datos usando scanner
int h;
int m;
int s;
Scanner scanner = new Scanner(System.in);
System.out.println("introduzca la hora");
h = scanner.nextInt(); //almacenas el dato
creamos el objeto con los datos de la variables que asignamos con scanner:
LocalTime lcl = LocalTime.of(h, m, s);
Si usa el scanner para crear el objeto tenga presente esto:
public static LocalTime of(int hour,
int minute,
int second)
Obtains an instance of LocalTime from an hour, minute and second.
This returns a LocalTime with the specified hour, minute and second. The nanosecond field will be set to zero.
Parameters:
- hour - the hour-of-day to represent, from 0 to 23
- minute - the minute-of-hour to represent, from 0 to 59
- second - the second-of-minute to represent, from 0 to 59
Returns:
the local time, not null
Throws:
DateTimeException - if the value of any field is out of range
Las horas, minutos y segundos están indexada a 0, ademas de tener en cuenta eso tendría que comprobar que los valores que obtiene del scanner no están fuera del rango y cumplen con ellos ya sea con el uso if
dentro de un bucle o lo que usted quiera.
...y luego operar con ellos...
//puede usar
import java.time.temporal.ChronoUnit;
//..
//supongamos tiene dos instancias
LocalTime suLocalTime1 = LocalTime.of(h, m, s);
LocalTime suLocalTime2 = LocalTime.of(10, 05, 03);
long hEntre = ChronoUnit.HOURS.between(suLocalTime1, suLocalTime2);
long mEntre = ChronoUnit.MINUTES.between(suLocalTime1, suLocalTime2);
System.out.println(hEntre);
System.out.println(mEntre);
Puede hacer uso de ChronoUnit con el método between puede hacer cálculos con objetos que implementen la interfaz temporal
, y LocalTime
es uno de ellos y calcular la cantidad de tiempo entre dos objetos temporales.
between(Temporal temporal1Inclusive, Temporal temporal2Exclusive)
... cambiar los valores (2, 3, 45)....
LocalTime es inmutable puede mirar los metodo que tiene.
Pero no se muy bien lo que quiere lograr, por ejemplo puede usar LocalTime.plusHours(long hoursToAdd)
para obtener una nueva instacia, a la que se le añaden horas ect, quizas eso es lo que busca al decir de cambiar los valores.
P.D: quizás para el scanner podría usar parse LocalTime leetTime = LocalTime.parse("10:10");
pero creo que solo funciona con Java 8.