Found 4336 Articles for Java 8

Duration getSeconds() method in Java

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

3K+ Views

The value of a duration in seconds can be obtained using the getSeconds() method in the Duration class in Java. This method requires no parameters and it returns the duration value in seconds.A program that demonstrates this is given as follows −Example Live Demoimport java.time.Duration; public class Demo {    public static void main(String[] args) {       Duration d = Duration.ofMinutes(5);       System.out.println("The duration is: " + d);       System.out.println("The duration in seconds is: " + d.getSeconds());    } }OutputThe duration is: PT5M The duration in seconds is: 300Now let us understand the above program.The ... Read More

LocalTime withHour() method in Java

Samual Sam
Updated on 30-Jul-2019 22:30:25

25 Views

An immutable copy of a LocalTime with the hour altered as required is done using the method withHour() in the LocalTime class in Java. This method requires a single parameter i.e. the hour that is to be set in the LocalTime and it returns the LocalTime with the hour altered as required.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; public class Main {    public static void main(String[] args) {       LocalTime lt1 = LocalTime.parse("23:15:30");       System.out.println("The LocalTime is: " + lt1);       LocalTime lt2 = lt1.withHour(5);       ... Read More

LocalTime withMinute() method in Java

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

37 Views

An immutable copy of a LocalTime with the minutes altered as required is done using the method withMinute() in the LocalTime class in Java. This method requires a single parameter i.e. the minute that is to be set in the LocalTime and it returns the LocalTime with the minute altered as required.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; public class Main {    public static void main(String[] args) {       LocalTime lt1 = LocalTime.parse("23:15:30");       System.out.println("The LocalTime is: " + lt1);       LocalTime lt2 = lt1.withMinute(45);       ... Read More

LocalTime isSupported() method in Java

Samual Sam
Updated on 30-Jul-2019 22:30:25

46 Views

It can be checked if a ChronoUnit is supported by the LocalTime class or not by using the isSupported() method in the LocalTime class in Java. This method requires a single parameter i.e. the ChronoUnit to check. It returns true if the ChronoUnit is supported by the LocalTime class and false otherwise.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; import java.time.temporal.*; public class Demo {    public static void main(String[] args) {       LocalTime lt = LocalTime.now();       System.out.println("The LocalTime is: " + lt);       boolean flag = lt.isSupported(ChronoUnit.HOURS);   ... Read More

LocalTime minus() method in Java

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

170 Views

An immutable copy of a LocalTime where the required duration is subtracted from it can be obtained using the minus() method in the LocalTime class in Java. This method requires two parameters i.e. the duration to be subtracted and the TemporalUnit of the duration. Also, it returns the LocalTime object with the required duration subtracted from it.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; import java.time.temporal.*; public class Demo {    public static void main(String[] args) {       LocalTime lt = LocalTime.now();       System.out.println("The LocalTime is: " + lt);       ... Read More

LocalTime plus() method in Java

Samual Sam
Updated on 30-Jul-2019 22:30:25

153 Views

An immutable copy of a LocalTime where the required duration is added to it can be obtained using the plus() method in the LocalTime class in Java. This method requires two parameters i.e. the duration to be added and the TemporalUnit of the duration. Also, it returns the LocalTime object with the required duration added to it.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; import java.time.temporal.*; public class Demo {    public static void main(String[] args) {       LocalTime lt = LocalTime.now();       System.out.println("The LocalTime is: " + lt);       ... Read More

LocalTime parse() method in Java

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

99 Views

The LocalTime instance can be obtained from a string value using the parse() method in the LocalTime class in Java. This method requires a single parameter i.e. the string which is to be parsed. This string cannot be null. Also, it returns the LocalTime instance obtained from the string value that was passed as a parameter.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; public class Demo {    public static void main(String[] args) {       LocalTime lt = LocalTime.parse("23:15:30");       System.out.println("The LocalTime is: " + lt);    } }OutputThe LocalTime is: 23:15:30Now ... Read More

LocalTime query() Method in Java

Samual Sam
Updated on 30-Jul-2019 22:30:25

35 Views

The LocalTime object can be queried as required using the query method in the LocalTime class in Java. This method requires a single parameter i.e. the query to be invoked and it returns the result of the query.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; import java.time.temporal.*; public class Demo {    public static void main(String[] args) {       LocalTime lt = LocalTime.parse("23:15:30");       System.out.println("The LocalTime is: " + lt);       String precision = lt.query(TemporalQueries.precision()).toString();       System.out.println("The Precision for the LocalTime is: "+ precision);    } }OutputThe LocalTime ... Read More

Duration toNanos() method in Java

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

73 Views

The value of a particular duration in the number of nanoseconds can be obtained using the toNanos() method in the Duration class in Java. This method requires no parameters and it returns the duration in the number of nanoseconds.A program that demonstrates this is given as follows −Example Live Demoimport java.time.Duration; public class Demo {    public static void main(String[] args) {       Duration d = Duration.ofSeconds(1);       System.out.println("The duration is: " + d);       System.out.println("The number of nanoseconds in the duration is: " + d.toNanos());    } }OutputThe duration is: PT1S The number of ... Read More

Duration toMillis() method in Java

Samual Sam
Updated on 30-Jul-2019 22:30:25

107 Views

The value of a particular duration in the number of milliseconds can be obtained using the toMillis() method in the Duration class in Java. This method requires no parameters and it returns the duration in the number of milliseconds.A program that demonstrates this is given as follows −Example Live Demoimport java.time.Duration; public class Demo {    public static void main(String[] args) {       Duration d = Duration.ofSeconds(1);       System.out.println("The duration is: " + d);       System.out.println("The number of milliseconds in the duration is: " + d.toMillis());    } }OutputThe duration is: PT1S The number of ... Read More

Advertisements