Found 9326 Articles for Object Oriented Programming

Instant range() method in Java

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

574 Views

The range of values for a field can be obtained using the range() method in the Instant class in Java. This method requires a single parameter i.e. the ChronoField for which the range of values are required and it returns the range of valid values for the ChronoField.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; import java.time.temporal.ChronoField; import java.time.temporal.ValueRange; public class Demo { public static void main(String[] args) { Instant i = Instant.now(); ValueRange range1 = i.range(ChronoField.MILLI_OF_SECOND); ... Read More

Instant toString() method in Java

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

165 Views

The range of values for a field can be obtained using the range() method in the Instant class in Java. This method requires a single parameter i.e. the ChronoField for which the range of values are required and it returns the range of valid values for the ChronoField.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; import java.time.temporal.ChronoField; import java.time.temporal.ValueRange; public class Demo { public static void main(String[] args) { Instant i = Instant.now(); ValueRange range1 = i.range(ChronoField.MILLI_OF_SECOND); ... Read More

Instant parse() method in Java

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

222 Views

The string representation of an Instant can be obtained using the toString() method in the Instant class in Java. This method requires no parameters and it returns the string representation of the Instant.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.toString()); } }OutputThe current Instant is: 2019-02-13T09:01:52.484ZNow let us understand the above program.The string representation of the current ... Read More

Instant truncatedTo() method in Java

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

552 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

102 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

534 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

115 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

162 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

Advertisements