Found 9326 Articles for Object Oriented Programming

Period ofMonths() method in Java

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

159 Views

The Period can be obtained with the given number of months using the ofMonths() method in the Period class in Java. This method requires a single parameter i.e. the number of months and it returns the Period object with the given number of months.A program that demonstrates this is given as follows −Example Live Demoimport java.time.Period; public class Demo { public static void main(String[] args) { int months = 11; Period p = Period.ofMonths(months); System.out.println("The Period is: " + p); ... Read More

Period ofDays() method in Java

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

252 Views

The Period can be obtained with the given number of days using the ofDays() method in the Period class in Java. This method requires a single parameter i.e. the number of days and it returns the Period object with the given number of days.A program that demonstrates this is given as follows −Example Live Demoimport java.time.Period; public class Demo { public static void main(String[] args) { int days = 5; Period p = Period.ofDays(days); System.out.println("The Period is: " + p); ... Read More

LocalDate minusMonths() Method in Java

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

605 Views

An immutable copy of the LocalDate where the months are subtracted from it can be obtained using the minusMonths() method in the LocalDate class in Java. This method requires a single parameter i.e. the number of months to be subtracted and it returns the instant with the subtracted 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

LocalDate minusWeeks() Method in Java

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

118 Views

An immutable copy of the LocalDate where the weeks are subtracted from it can be obtained using the minusWeeks() method in the LocalDate class in Java. This method requires a single parameter i.e. the number of weeks to be subtracted and it returns the instant with the subtracted weeks.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

LocalDate minusDays() Method in Java

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

180 Views

An immutable copy of the LocalDate where the days are subtracted from it can be obtained using the minusDays() method in the LocalDate class in Java. This method requires a single parameter i.e. the number of days to be subtracted and it returns the instant with the subtracted days.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

LocalDate plusYears() method in Java

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

633 Views

An immutable copy of the LocalDate where the years are added to it can be obtained using the plusYears() method in the LocalDate class in Java. This method requires a single parameter i.e. the number of years to be added and it returns the instant with the added years.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

LocalDate plusDays() Method in Java

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

3K+ Views

An immutable copy of the LocalDate where the days are added to it can be obtained using the plusDays() method in the LocalDate class in Java. This method requires a single parameter i.e. the number of days to be added and it returns the instant with the added days.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);       LocalDate ld2 = ld1.plusDays(5);       System.out.println("The LocalDate after ... Read More

LocalDate plusWeeks() method in Java

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

202 Views

An immutable copy of the LocalDate where the weeks are added to it can be obtained using the plusWeeks() method in the LocalDate class in Java. This method requires a single parameter i.e. the number of weeks to be added and it returns the instant with the added weeks.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

LocalDate plusMonths() method in Java

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

786 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

176 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

Advertisements