Java Date Time

Converting between Date to LocalDate

Learn to convert from java.time.LocalDate to java.util.Date and vice-versa using the easy-to-understand Java examples. 1. Convert Date to LocalDate The Date.getTime() method returns the epoch milliseconds i.e. the number of milliseconds since January 1, 1970, 00:00:00 GMT. To get the LocalDate, we need to first set the zone offset information …

How to Format LocalDateTime in Java

Java example of formatting LocalDateTime instance to String using default formats in DateTimeFormatter class and format to custom patterns.

How To Measure Elapsed Time in Java

Learn to calculate execution time or elapsed time of program or some statements using System.nanoTime() or System.currentTimeMillis() methods.

Get Current Timestamp in Java

In Java, timestamps should be represented with java.time.Instant from Java 8, and java.sql.Timestamp till Java 7. Learn to get current timestamp in java.

Compare Two Dates in Java

Learn to compare two given dates in Java to find out which date is earlier and which is later in the universal timeline. We will see date comparison examples using the following classes: 1. Date Comparison since Java 8 1.1. Core Classes The most used date classes in Java 8 …

Converting Date to EST/EDT Timezone

Java supports three timezone constants for Eastern Standard Time i.e. “EST”, “America/New_York” and “EST5EDT”. Learn to convert date to EST in Java.

Get all Dates between Two Dates as Stream

Date and time handling has always been a pain area for Java developers. The new Date-Time API added in Java 8 changed the way, we interact with date and time in Java. New Date API is a very powerful and much-needed improvement. The only thing missing was, getting a stream …

Java XMLGregorianCalendar

Learn to convert XMLGregorianCalendar to Date class or string value. Also learn to apply timezone changes and daylight saving effects as well.

Format XMLGregorianCalendar to String

Learn to format XMLGregorianCalendar instance to string in multiple patterns e.g. ‘MM/dd/yyyy hh:mm a z’ using DateTimeFormatter and SimpleDateFormat classes in Java.

Java Locale: A Comprehensive Guide

Learn about Localization and Internationalization with Locale. Learn to create Locale objects and use them for formatting dates and messages.

Parse a String to Date in Java 8

Learn to convert a string to date in Java 8 using the new date time API classes such as LocalDate, LocalDateTime, ZonedDateTime and DateTimeFormatter. 1. Convert string to date in ISO8601 format By default, java dates are in ISO8601 format, so if you have any string which represents a date …

Guide to java.util.Date Class

Learn to create new date, get current date, parse date to string or format Date object using java.util.Date class. These use-cases are frequently required, and having them in one place will help in saving time for many of us.

Get Current Date and Time in Java

Java offers many useful ways to get current date or current time using Date, Calendar and newly introduced LocalDate, LocalDateTime and ZonedDateTime classes in Java 8 Date/Time API classes.

Java – Difference Between Two Dates

Learn to find difference between two dates in days, months or any other time units – using Java 8 classes such as Duration, ChronoUnit and finally JodaTime.

Java 8 Date Time API

Java 8 contains the new Date and Time APIs/classes (JSR-310), called ThreeTen, which will change how you have been handling dates in Java.

Java Strict Date Validation – SimpleDateFormat.setLenient()

All of us have come across situations when we have to parse user input for validation. Other fields such as text or numeric are rather easy, but Java date validation is a little bit difficult, and a small error can leave the application in an unstable state. 1. Java Date …

About Us

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.