Created: 2023-08-30 18:23
Status: #concept
Subject: Programming
Tags: Java Java Class Java Package
java.time.LocalDate
It exposes the
LocalDate.now()
static
Method to return a LocalDate
object with the date during the time the code executes.
It does not store the time.
import java.time.LocalDate;
public class Example {
public static void main(String[] args) {
LocalDate now = LocalDate.now();
int year = now.getYear();
int month = now.getMonthValue();
int day = now.getDayOfMonth();
System.out.println("today is " + day + "." + month + "." + year);
}
}
Instance Methods
.getDayOfMonth(): int
.getMonth(): Month
returns anenum
for months likeJANUARY
, etc..getMonthValue(): int
returns an integer from1
to12
.
.getYear(): int
returns the year field..getDayOfWeek(): DayOfWeek
returns anenum
forMONDAY
,TUESDAY
,WEDNESDAY
, etc..equals(Object obj): boolean
checks if theLocalDate
is equal toobj
..isLeapYear(): boolean
returnstrue
if resides in a leap year date.