Found 34469 Articles for Programming

LocalDateTime plusDays() method in Java

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

184 Views

An immutable copy of a LocalDateTime object where some days are added to it can be obtained using the plusDays() method in the LocalDateTime class in Java. This method requires a single parameter i.e. the number of days to be added and it returns the LocalDateTime object 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) {       LocalDateTime ldt = LocalDateTime.now();       System.out.println("The current LocalDateTime is: " + ldt);       System.out.println("The LocalDateTime with 10 days added is: ... Read More

LocalDateTime plusMonths() method in Java

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

105 Views

An immutable copy of a LocalDateTime object where some months are added to it can be obtained using the plusMonths() method in the LocalDateTime class in Java. This method requires a single parameter i.e. the number of months to be added and it returns the LocalDateTime object 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) {       LocalDateTime ldt = LocalDateTime.now();       System.out.println("The current LocalDateTime is: " + ldt);       System.out.println("The LocalDateTime with 5 months added is: ... Read More

LocalDateTime plusNanos() method in Java

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

108 Views

An immutable copy of a LocalDateTime object where some nanoseconds are added to it can be obtained using the plusNanos() method in the LocalDateTime class in Java. This method requires a single parameter i.e. the number of nanoseconds to be added and it returns the LocalDateTime object with the added nanoseconds.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; public class Demo {    public static void main(String[] args) {       LocalDateTime ldt = LocalDateTime.now();       System.out.println("The current LocalDateTime is: " + ldt);       System.out.println("The LocalDateTime with 1000 nanoseconds added is: ... Read More

LocalDate getChronology() method in Java

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

57 Views

The value of the specified field from the LocalDate can be obtained using the get() method in the LocalDate class in Java. This method requires a single parameter i.e. ChronoField that is required and it returns the value of the specified field from the LocalDate.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; import java.time.temporal.ChronoField; public class Main {    public static void main(String[] args) {       LocalDate ld = LocalDate.parse("2019-02-16");       System.out.println("The LocalDate is: " + ld);       System.out.println("The DAY_OF_MONTH is: " + ld.get(ChronoField.DAY_OF_MONTH));    } }OutputThe LocalDate is: 2019-02-16 ... Read More

LocalDate get() method in Java

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

81 Views

The value of the specified field from the LocalDate can be obtained using the get() method in the LocalDate class in Java. This method requires a single parameter i.e. ChronoField that is required and it returns the value of the specified field from the LocalDate.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; import java.time.temporal.ChronoField; public class Main {    public static void main(String[] args) {       LocalDate ld = LocalDate.parse("2019-02-16");       System.out.println("The LocalDate is: " + ld);       System.out.println("The DAY_OF_MONTH is: " + ld.get(ChronoField.DAY_OF_MONTH));    } }OutputThe LocalDate is: 2019-02-16 ... Read More

LocalDate format() method in Java

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

72 Views

The LocalDate can be formatted with the specified formatter using the format() method in the LocalDate class in Java. This method requires a single parameter i.e. the LocalDate object to be formatted and it returns the formatted LocalDate with the specified formatter.A program that demonstrates this is given as follows −Example Live Demoimport java.util.*; import java.time.*; import java.time.format.DateTimeFormatter; public class Main {    public static void main(String[] args) {       LocalDate ld = LocalDate.parse("2019-02-14");       System.out.println("The LocalDate is: " + ld);       DateTimeFormatter dtf = DateTimeFormatter.ofPattern("dd/MM/YYYY");       System.out.println("The formatted LocalDate is: " + ... Read More

LocalDate from() method in Java

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

83 Views

An instance of a LocalDate object can be obtained from a Temporal object using the from() method in the LocalDate class in Java. This method requires a single parameter i.e. the Temporal object and it returns the LocalDate object that is obtained from the Temporal object.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; public class Main {    public static void main(String[] args) {       LocalDate ld = LocalDate.from(ZonedDateTime.now());       System.out.println("The LocalDate is: " + ld);    } }OutputThe LocalDate is: 2019-02-16Now let us understand the above program.The instance of the LocalDate ... Read More

LocalDate compareTo() method

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

3K+ Views

Two LocalDate objects can be compared using the compareTo() method in the LocalDate class in Java. This method requires a single parameter i.e. the LocalDate object to be compared.If the first LocalDate object is greater than the second LocalDate object it returns a positive number, if the first LocalDate object is lesser than the second LocalDate object it returns a negative number and if both the LocalDate objects are equal it returns zero.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 ... Read More

LocalDate isLeapYear() method in Java

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

70 Views

It can be checked if the LocalDate is in a leap year or not using the isLeapYear() method in the LocalDate class in Java. This method requires no parameters. It returns true if the LocalDate is in a leap year and false otherwise.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; public class Main {    public static void main(String[] args) {       LocalDate ld = LocalDate.parse("2012-10-12");       System.out.println("The LocalDate is: " + ld);       boolean flag = ld.isLeapYear();       if(flag)          System.out.println("This is a leap ... Read More

LocalDate isEqual() method in Java

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

991 Views

It can be checked if two LocalDate objects are equal or not using the isEqual() method in the LocalDate class in Java. This method requires a single parameter i.e. the LocalDate object that is to be compared. It returns true if the two LocalDate objects are equal and false otherwise.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-12");       LocalDate ld2 = LocalDate.parse("2019-02-12");       System.out.println("The LocalDate ld1 is: " + ld1);       System.out.println("The ... Read More

Advertisements