Found 9150 Articles for Object Oriented Programming

LocalDate plusMonths() method in Java

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

1K+ Views

An immutable copy of the LocalDate where the months are added to it can be obtained using the plusMonths() method in the LocalDate class in Java. This method requires a single parameter i.e. the number of months to be added and it returns the instant with the added months.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; public class Demo { public static void main(String[] args) { LocalDate ld1 = LocalDate.parse("2019-02-14"); System.out.println("The LocalDate is: " + ld1); ... Read More

Instant get() method in Java

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

227 Views

The value of the required ChronoField for an Instant can be obtained using the get() method in the Instant class in Java. This method requires a single parameter i.e. the ChronoField and it returns the value of the ChronoField that was passed as a parameter.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();       int micro = i.get(ChronoField.MICRO_OF_SECOND);       System.out.println("The current Instant is: " + i);       System.out.println("The MICRO_OF_SECOND ... Read More

Instant range() method in Java

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

740 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

260 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

308 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

940 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

159 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

4K+ 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

685 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

Advertisements