Close

Java Date Time - LocalTime.now() Examples

Java Date Time Java Java API 


Class:

java.time.LocalTime

java.lang.Objectjava.lang.Objectjava.time.LocalTimejava.time.LocalTimejava.time.temporal.TemporalTemporaljava.time.temporal.TemporalAdjusterTemporalAdjusterjava.lang.ComparableComparablejava.io.SerializableSerializableLogicBig

Methods:

public static LocalTime now()

Returns the current local time instance from the system clock in the default time-zone.


public static LocalTime now(ZoneId zone)

Returns the current local time instance from the system clock, adjusting fields values to the specified time-zone.


public static LocalTime now(Clock clock)

Returns the current local time instance from the provided Clock.



Examples


package com.logicbig.example.localtime;

import java.time.LocalTime;

public class NowExample {

public static void main (String... args) {
LocalTime t = LocalTime.now();
System.out.println(t);
}
}

Output

16:25:07.969




package com.logicbig.example.localtime;

import java.time.LocalTime;
import java.time.ZoneId;

public class NowExample2 {

public static void main (String... args) {
LocalTime t = LocalTime.now(ZoneId.of("Japan"));
System.out.println(t);
}
}

Output

06:25:10.211




package com.logicbig.example.localtime;

import java.time.Clock;
import java.time.LocalTime;

public class NowExample3 {

public static void main (String... args) {
LocalTime t = LocalTime.now(Clock.systemDefaultZone());
System.out.println(t);

}
}

Output

16:25:12.333




See Also