Found 4336 Articles for Java 8

Instant truncatedTo() method in Java

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

578 Views

An immutable truncated Instant can be obtained using the truncatedTo() method in the Instant class in Java. This method requires a single parameter i.e. the TemporalUnit till which the Instant is truncated and it returns the immutable truncated Instant.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; import java.time.temporal.ChronoUnit; public class Demo { public static void main(String[] args) { Instant instant = Instant.now(); System.out.println("The current instant is: " + instant); Instant truncatedInstant = instant.truncatedTo(ChronoUnit.MINUTES); ... Read More

Instant isSupported() method in Java

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

104 Views

It can be checked if a ChronoUnit is supported by the Instant class or not by using the isSupported() method in the Instant 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 Instant class and false otherwise.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; import java.time.temporal.ChronoUnit; public class Demo {    public static void main(String[] args) {       Instant i = Instant.now();       System.out.println("The current instant is: " + i);       boolean flag = i.isSupported(ChronoUnit.SECONDS); ... Read More

Instant minus() method in Java

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

2K+ Views

An immutable copy of a instant where a time unit is subtracted from it can be obtained using the minus() method in the Instant class in Java. This method requires two parameters i.e. time to be subtracted from the instant and the unit in which it is to be subtracted. It also returns the immutable copy of the instant where the required time unit is subtracted.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; import java.time.temporal.ChronoUnit; public class Demo { public static void main(String[] args) { Instant i ... Read More

Instant plus() method in Java

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

2K+ Views

An immutable copy of a instant where a time unit is added to it can be obtained using the plus() method in the Instant class in Java. This method requires two parameters i.e. time to be added to the instant and the unit in which it is to be added. It also returns the immutable copy of the instant where the required time unit is added.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; import java.time.temporal.ChronoUnit; public class Demo { public static void main(String[] args) { Instant i ... Read More

Instant until() Method in Java

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

538 Views

The time between two instant objects can be calculated using the until() method in the Instant class in Java. This method requires two parameters i.e. the end instant and the chronological unit to measure the time. It returns the time between two instant objects.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; import java.time.temporal.ChronoUnit; public class Demo { public static void main(String[] args) { Instant i1 = Instant.parse("2019-01-13T11:45:13.00Z"); Instant i2 = Instant.parse("2019-01-13T15:30:12.00Z"); long time = i1.until(i2, ... Read More

Instant minusNanos() method in Java

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

117 Views

An immutable copy of a instant where some nanoseconds are subtracted from it can be obtained using the minusNanos() method in the Instant class in Java. This method requires a single parameter i.e. the number of nanoseconds to be subtracted and it returns the instant with the subtracted nanoseconds.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; public class Demo { public static void main(String[] args) { Instant i = Instant.now(); System.out.println("The current instant is: " + i); ... Read More

Instant minusMillis() method in Java

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

164 Views

An immutable copy of a instant where some milliseconds are subtracted from it can be obtained using the minusMillis() method in the Instant class in Java. This method requires a single parameter i.e. the number of milliseconds to be subtracted and it returns the instant with the subtracted milliseconds.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; public class Demo { public static void main(String[] args) { Instant i = Instant.now(); System.out.println("The current instant is: " + i); ... Read More

Duration compareTo() method in Java

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

6K+ Views

Two durations can be compared using the compareTo() method in the Duration class in Java. This method requires a single parameter i.e. the duration to be compared.If the first duration is greater than the second duration it returns a positive number, if the first duration is lesser than the second duration it returns a negative number and if both the durations are equal it returns zero.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 d1 = Duration.ofHours(8); ... Read More

Duration ZERO field in Java

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

385 Views

The ZERO field sets the duration to zero in the Duration class in Java. This field is quite the same as the null value in different data types in Java.A program that demonstrates the ZERO field is given as follows −Example Live Demoimport java.time.Duration; public class Demo {    public static void main(String[] args) {       Duration d = Duration.ZERO;       boolean flag = d.isZero();       System.out.println("The duration is: " + d);       if(flag)          System.out.println("The above duration is of zero length");       else         ... Read More

Duration ofDays() method in Java

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

90 Views

The duration can be obtained in a 24 hour format using the ofDays() method in the Duration class in Java. This method requires a single parameter i.e. the number of days and it returns the duration in a 24 hour format. If the capacity of the duration is exceeded, then the ArithmeticException is thrown.A program that demonstrates this is given as follows −Example Live Demoimport java.time.Duration; public class Demo { public static void main(String[] args) { long days = 1; Duration duration = Duration.ofDays(days); ... Read More

Advertisements