Java API Time 8 - LocalTime

package com.codemonkey; import static java.lang.System.out; import java.time.LocalTime; import java.time.temporal.ChronoUnit; public class Main{ public static void main(String[] args){ getLocalTimeDemo(); } public static void getLocalTimeDemo(){ LocalTime localTimeA = LocalTime.now(); out.println(localTimeA);//18:35:54.020553 out.println("Hora:"+localTimeA.getHour());//18 out.println("Minutos:"+localTimeA.getMinute());//35 out.println("Segundos:"+localTimeA.getSecond());//54 out.println("Nano segundos:"+localTimeA.getNano());//020553 out.println("-------------------"); CharSequence charSequence="05:34"; LocalTime localTimeB = LocalTime.parse(charSequence); out.println(localTimeB);//05:34 int hora=4; int minutos=15; LocalTime localTimeC = LocalTime.of(hora,minutos); out.println(localTimeC);//04:15 LocalTime localTimeD = LocalTime.parse("05:25").plus(2,ChronoUnit.HOURS); out.println(localTimeD);//07:25 LocalTime localTimeE = localTimeD.minus(1, ChronoUnit.HOURS); out.println(localTimeE);//06:25 hora = localTimeE.getHour(); out.println("Hora:"+hora);//6 if(LocalTime.parse("05:30").isBefore(LocalTime.parse("06:30"))){ out.println(LocalTime.parse("05:30").toString()); } if(LocalTime.parse("07:30").isAfter(LocalTime.parse("06:30"))){ out.println(LocalTime.parse("07:30").toString()); } out.println(LocalTime.MIDNIGHT);//00:00 out.println(LocalTime.MAX);//23:59:59.999999999 LocalTime localTimeF = LocalTime.of(12,5); LocalTime localTimeG = LocalTime.of(12,5,2); LocalTime localTimeH = LocalTime.of(12,5,2,389000); out.println(localTimeF);//12:05 out.println(localTimeG);//12:05:02 out.println(localTimeH);//12:05:02.000389 LocalTime localTimeI = LocalTime.parse("04:26"); out.println(localTimeI);//04:26 } }
Ejemplos de uso de LocalTime (java.time.LocalTime)

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.