This method is used to get lenght of a month in the date. The length of a month represents the total number of days in a month. For example, we have a date 2012/01/25 then this method returns 31 as a result.
It does not take any argument but returns an integer value. The syntax of the method is given below.
public boolean equals(Object obj)
It does not take any argument.
It returns an integer value.
Let's take an example to get length of month. Here, we are getting October month's length which is 31. So the method returns 31 as a result.
import java.time.LocalDateTime;
/*
* Example to Check two LocalDateTime are equal?
*/
public class JExercise {
public static void main(String[] args) {
// Create a LocalDateTime date
LocalDateTime datetime = LocalDateTime.parse("2012-05-02T02:30:10");
// Print Date and time
System.out.println("Date and Time : "+datetime);
// Create another LocalDateTime date
LocalDateTime datetime2 = LocalDateTime.parse("2012-05-02T02:30:10");
// Print Date and time
System.out.println("2nd Date and Time : "+datetime2);
boolean eq = datetime.equals(datetime2);
System.out.println("Is both dates equal : "+eq);
}
}
Output:
Date and Time : 2012-05-02T02:30:10
2nd Date and Time : 2012-05-02T02:30:11
Is both dates equal : false
Let's take another example to understand the use of lengthOfMonth() method. Here, we are getting length of February month that has either 28 or 29. So based on the year, it returns 28 as a result.
import java.time.LocalDateTime;
/*
* Example to Check two LocalDateTime are equal?
*/
public class JExercise {
public static void main(String[] args) {
// Create a LocalDateTime date
LocalDateTime datetime = LocalDateTime.now();
// Print Date and time
System.out.println("Date and Time : "+datetime);
// Create another LocalDateTime date
LocalDateTime datetime2 = LocalDateTime.parse("2012-05-02T02:30:11");
// Print Date and time
System.out.println("2nd Date and Time : "+datetime2);
boolean eq = datetime.equals(datetime2);
System.out.println("Is both dates equal : "+eq);
}
}
Output:
Date and Time : 2020-06-09T12:27:41.485375
2nd Date and Time : 2012-05-02T02:30:11
Is both dates equal : false
Well, in this topic, we learnt To add number of days to a date which is created by LocalDate class. This method returns a copy of date after adding the days, notice the examples we provided.
If we missed something, you can suggest us at - info.javaexercise@gmail.com