Java LocalDate: Create, Parse, Format and Compare Dates
Java LocalDate examples on Java 25. Create, parse and format dates, add days and months, compare dates and convert LocalDate to other date types.
Java provides the java.time package (introduced in Java 8) for handling date and time. This package offers comprehensive date and time functionality, making it easier to work with date and time values accurately and effectively.
Learn More.
Java LocalDate examples on Java 25. Create, parse and format dates, add days and months, compare dates and convert LocalDate to other date types.
Java DateTimeFormatter examples for formatting and parsing LocalDate, LocalDateTime and ZonedDateTime with ofPattern() letters, ISO constants, FormatStyle and Locale, plus DateTimeParseException handling and the yyyy vs YYYY mistake.
Convert LocalDate to java.sql.Date and LocalTime to java.sql.Time, or skip both with JDBC 4.2 setObject() and getObject(), JPA and Hibernate.
Convert Date to LocalDate in Java with LocalDate.ofInstant() and back with Date.from(), pick the right time zone and avoid the one-day-off bug.
Convert LocalDateTime to Date in Java with atZone() and Date.from(), and back with ofInstant(), including DST gaps, overlaps and lost nanoseconds.
Convert LocalDateTime to ZonedDateTime in Java with atZone(), ofLocal() and ofStrict(), see how DST gaps and overlaps resolve, and convert back safely.
Convert date and time between time zones in Java with withZoneSameInstant(), from Instant, OffsetDateTime or LocalDateTime, with DST-safe examples.
Learn to add days to a date in Java with plusDays(), plusMonths() and plusYears(), with month-end rules, leap years, DST and java.util.Date conversion.
Format LocalDateTime in Java with format() and DateTimeFormatter. ISO and custom patterns, AM/PM, millis, locales, zones and pattern mistakes to avoid.
Measure elapsed time in Java with System.nanoTime() and Duration, avoid wall-clock errors, time any task with a helper, and use JMH for benchmarks.
Get the current timestamp in Java with Instant.now() and currentTimeMillis(), convert to epoch millis or seconds, format it, and save it with JDBC.
Compare two dates in Java with isBefore(), isAfter(), isEqual() and compareTo(), with or without time, across time zones, in ranges and for legacy Date.
Convert date and time to EST in Java with America/New_York, which switches between EST and EDT. Compare EST5EDT and EST and print the right zone label.
Java Locale examples on Java 25. Create locales with Locale.of() and forLanguageTag(), set the default, match Accept-Language and format dates and numbers.
Get the current date and time in Java with LocalDate, LocalDateTime, ZonedDateTime and Instant now(), in any time zone, formatted and testable.
Find the difference between two dates in Java in years, months, days, hours and minutes with Period, Duration and ChronoUnit, including DST cases.
Format currency in Java with NumberFormat.getCurrencyInstance(), Locale and BigDecimal. Switch currencies, parse amounts safely and control rounding.
Get the current locale in Java with Locale.getDefault(), the FORMAT category, request.getLocale() and LocaleContextHolder, and pass it to formatters.
Calculate age from date of birth in Java with Period.between() and ChronoUnit, plus leap-day birthdays, time zones, parsing and a minimum age check.
HowToDoInJava provides tutorials and how-to guides on Java and related technologies.
It also shares the best practices, algorithms & solutions and frequently asked interview questions.