concept LocalDate in category java

appears as: LocalDate, LocalDate
Modern Java in Action: Lambdas, streams, reactive and functional programming

This is an excerpt from Manning's book Modern Java in Action: Lambdas, streams, reactive and functional programming.

We start by exploring how to create simple dates and intervals. The java.time package includes many new classes to help you: LocalDate, LocalTime, LocalDateTime, Instant, Duration, and Period.

12.1.1. Working with LocalDate and LocalTime

The class LocalDate probably is the first one you’ll come across when you start using the new Date and Time API. An instance of this class is an immutable object representing a plain date without the time of day. In particular, it doesn’t carry any information about the time zone.

You can create a LocalDate instance by using the of static factory method. A LocalDate instance provides many methods to read its most commonly used values (year, month, day of the week, and so on), as shown in the following listing.

Listing 12.1. Creating a LocalDate and reading its values
LocalDate date = LocalDate.of(2017, 9, 21);   #1
int year = date.getYear();                    #2
Month month = date.getMonth();                #3
int day = date.getDayOfMonth();               #4
DayOfWeek dow = date.getDayOfWeek();          #5
int len = date.lengthOfMonth();               #6
boolean leap = date.isLeapYear();             #7
OCA Java SE 8 Programmer I Certification Guide

This is an excerpt from Manning's book OCA Java SE 8 Programmer I Certification Guide.

Watch out for the count and type of arguments passed to the instance method format. When calling format on a LocalDate, LocalTime, or LocalDateTime instance, pass a DateTimeFormatter instance as a method parameter. When calling format on DateTimeFormatter, pass a LocalDate, LocalTime, or LocalDateTime instance as a method argument.

The method format in DateTimeFormatter formats a date or time object to a String using the rules of the formatter. The following example formats a LocalDate object using the style FormatStyle (styles are listed in table 4.2):

What happens if you pass a time object (LocalTime) instead of a date object (LocalDate) in the preceding code? Will it compile or execute successfully (changes are shown in bold)?

The LocalDate class defines methods with the names minusXX(), plusXX(), and withXX() to manipulate the date values. The API architects have used the names that make their purpose explicit. Because LocalDate is an immutable class, all the methods create and return a copy. The minusXX() methods return a copy of the date with the specified days, months, or years subtracted from it:

Java 8 in Action: Lambdas, streams, and functional-style programming

This is an excerpt from Manning's book Java 8 in Action: Lambdas, streams, and functional-style programming.

Let’s start by exploring how to create simple dates and intervals. The java.time package includes many new classes to help you: LocalDate, LocalTime, LocalDateTime, Instant, Duration, and Period.

12.1.1. Working with LocalDate and LocalTime

The class LocalDate is probably the first one you’ll come across when you start using the new Date and Time API. An instance of this class is an immutable object representing just a plain date without the time of day. In particular, it doesn’t carry any information about the time zone.

You can create a LocalDate instance using the of static factory method. A LocalDate instance provides many methods to read its most commonly used values such as year, month, day of the week, and so on, as shown in the listing that follows.

Listing 12.1. Creating a LocalDate and reading its values
LocalDate date = LocalDate.of(2014, 3, 18); #1 int year = date.getYear(); #2 Month month = date.getMonth(); #3 int day = date.getDayOfMonth(); #4 DayOfWeek dow = date.getDayOfWeek(); #5 int len = date.lengthOfMonth(); #6 boolean leap = date.isLeapYear(); #7 #1: 2014-03-18 #2: 2014 #3: MARCH #4: 18 #5: TUESDAY #6: 31 (days in March) #7: false (not a leap year)