Found 9326 Articles for Object Oriented Programming

LocalDate withYear() method in Java

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

125 Views

An immutable copy of a LocalDate with the year altered as required is done using the method withYear() in the LocalDate class in Java. This method requires a single parameter i.e. the year that is to be set in the LocalDate and it returns the LocalDate with the year altered as required.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; public class Main { public static void main(String[] args) { LocalDate ld1 = LocalDate.parse("2019-02-15"); System.out.println("The LocalDate is: " + ld1); ... Read More

LocalDate range() method in Java

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

417 Views

The range of values for a ChronoField can be obtained using the range() method in the LocalDate class in Java. This method requires a single parameter i.e. the ChronoField for which the range of values is required and it returns the range of values.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 Main { public static void main(String[] args) { LocalDate ld = LocalDate.parse("2019-02-15"); System.out.println("The LocalDate is: " + ld); ... Read More

LocalDate toString() method in Java

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

234 Views

The string value of the LocalDate object can be obtained using the method toString() in the LocalDate class in Java. This method requires no parameters and it returns the string value of the LocalDate object.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: " + ld.toString()); } }OutputThe LocalDate is: 2019-02-15Now let us understand the above program.The string value of the LocalDate ... Read More

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

446 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

161 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

111 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

189 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

106 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

139 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

Advertisements