LocalDate todayIST = LocalDate.now(ZoneId.of("IST")) LocalDate todayKolkata = LocalDate.now(ZoneId.of("Asia/Kolkata")) Current date in "Asia/Kolkata", you can get it from ZoneId javadoc Invalid date 'February 29' as '2014' is not a leap year Try creating date by providing invalid inputs LocalDate firstDay_2014 = LocalDate.of(2014, Month.JANUARY, 1) Creating LocalDate by providing input arguments It’s time now to look into most important classes of Date Time API with examples. We have looked into most of the important parts of Java Date Time API.
: This package contains classes used for formatting and parsing date-time objects.We can extend AbstractChronology class to create our own calendar system. : This package defines generic APIs for non-ISO calendar systems.Most of the time, these classes will be sufficient for handling common requirements. All of these classes are immutable and thread-safe.
All the major base classes are part of this package, such as LocalDate, LocalTime, LocalDateTime, Instant, Period, Duration, etc.
Date class doesn’t provide internationalization, there is no timezone support.It’s one of the biggest problems with Java Date and Calendar classes. All the Date classes are mutable, so they are not thread-safe.Usually, the SimpleDateFormat class is used for parsing and formatting. We have abstract class for parsing and formatting need. There are no clearly defined classes for time, timestamp, formatting, and parsing.Also, both the classes have the same name, which is a very bad design itself. Having this in java.sql package doesn’t make any sense. contains both date and time values whereas contains only date value.Again formatting and parsing classes are defined in java.text package. Java Date Time classes are not defined consistently, we have Date Class in both java.util as well as java.sql packages.