Convert Date to LocalDate in Java (and LocalDate to Date)
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 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.
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.