Found 4336 Articles for Java 8

LocalDate minus() method in Java

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

2K+ Views

An immutable copy of a LocalDate where the required duration is subtracted from it can be obtained using the minus() method in the LocalDate 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 LocalDate 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) { LocalDate ld = LocalDate.parse("2019-02-15"); System.out.println("The ... Read More

LocalDate plus() method in Java

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

456 Views

An immutable copy of a LocalDate where the required duration is added to it can be obtained using the plus() method in the LocalDate 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 LocalDate 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) { LocalDate ld = LocalDate.parse("2019-02-15"); System.out.println("The ... Read More

LocalDate parse() method in Java

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

165 Views

The LocalDate instance can be obtained from a string value using the parse() method in the LocalDate 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 LocalDate 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) { LocalDate ld = LocalDate.parse("2019-02-15"); System.out.println("The LocalDate is: " ... Read More

LocalDate query() Method in Java

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

113 Views

The LocalDate object can be queried as required using the query method in the LocalDate 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) { LocalDate ld = LocalDate.parse("2019-02-14"); System.out.println("The LocalDate is: " + ld); String precision = ld.query(TemporalQueries.precision()).toString(); ... Read More

LocalDate now() Method in Java

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

194 Views

The current date can be obtained from the system clock in the default time zone using the now() method in the LocalDate class in Java. This method requires no parameters and it returns the current date from the system clock in the default time zoneA program that demonstrates this is given as follows −Example Live Demoimport java.time.*; public class Demo { public static void main(String[] args) { LocalDate ld = LocalDate.now(); System.out.println("The LocalDate is: " + ld); } }OutputThe LocalDate is: 2019-02-15Now let ... Read More

Period ofWeeks() method in Java

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

110 Views

The Period can be obtained with the given number of weeks using the ofWeeks() method in the Period class in Java. This method requires a single parameter i.e. the number of weeks and it returns the Period object with the given number of weeks.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 weeks = 7; Period p = Period.ofWeeks(weeks); System.out.println("The Period is: " + p); ... Read More

Period ofYears() method in Java

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

141 Views

The Period can be obtained with the given number of years using the ofYears() method in the Period class in Java. This method requires a single parameter i.e. the number of years and it returns the Period object with the given number of years.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 years = 3; Period p = Period.ofYears(years); System.out.println("The Period is: " + p); ... Read More

Period ofMonths() method in Java

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

160 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

254 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

614 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

Advertisements