date and time in Java

There are four choices in Java for date and time.
Type | Meaning
----- | -----
LocalDate | Contains just a date—no time and no time zone. 
LocalTime | Contains just a time—no date and no time zone. 
LocalDateTime | Contains both a date and time but no time zone. 
ZonedDateTime | Contains a date, time, and time zone. 

```
import java.time.*;  // import time classes
public class Main {
    public static void main(String args[]) {
        System.out.println(LocalDate.now());
        System.out.println(LocalTime.now());
        System.out.println(LocalDateTime.now());
        System.out.println(ZonedDateTime.now());
    }
}
```
Output:
```
2021-03-02
16:56:11.711
2021-03-02T16:56:11.711
2021-03-02T16:56:11.712Z[America/New_York]
```
<b>Format</b>
* <b>MMMM</b> M represents the month. The more M s you have, the more verbose the Java output. For example, M outputs 1, MM outputs 01, MMM outputs Jan, and MMMM outputs January.
* <b>dd</b> d represents the day in the month. As with month, the more d s you have, the more verbose the Java output. dd means to include the leading zero for a single-digit day. d means there is no leading zero.
* <b>,</b> Use , if you want to output a comma (this also appears after the year).
* <b>yyyy</b> y represents the year. yy outputs a two-digit year and yyyy outputs a four-digit year.
* <b>hh</b> h represents the hour. Use hh to include the leading zero if you’re outputting a single-digit hour.
* <b>:</b> Use : if you want to output a colon.
* <b>m</b> represents the minute omitting the leading zero if present. mm is more common and represents the minutes using two digits.

Methods in LocalDate, LocalTime, and LocalDateTime
| | Can call on LocalDate? | Can call on LocalTime? | Can call on LocalDateTime?
| ------ | ------ |----- | ----- 
|plusYears/minusYears | Yes | No | Yes
|plusMonths/minusMonths | Yes | No | Yes
|plusWeeks/minusWeeks | Yes | No | Yes
|plusDays/minusDays | Yes | No | Yes
|plusHours/minusHours | No | Yes | Yes
|plusMinutes/minusMinutes | No | Yes | Yes
|plusSeconds/minusSeconds | No | Yes | Yes
|plusNanos/minusNanos | No | Yes | Yes


Note any changes made to an instance will create a new object instead of modifying the existing one, cause they are immutable.
```
import java.time.LocalTime;
import java.time.temporal.ChronoField;

class Main {
    public static void main(String[] args) {
        LocalTime localTime = LocalTime.of(1, 15, 30);
        localTime.withHour(2).with(ChronoField.MINUTE_OF_HOUR, 30).plusSeconds(10);
        System.out.println(localTime); // 01:15:30
    }
}
```