Date and Time in Java

  1. LocalDate represents just a date(year, month, day) — not time.
  2. LocalTime represents only a time(hours, minutes, seconds, nanoseconds).
  3. LocalDateTime represents date and time.


  • We can add and subtract years, months, days, and weeks from our date object.
  • Note LocalDate is an immutable object so, in order to change it, we need to reassign it and most of the methods return an instance of it.
  • We can get a local date in different string formats by using class. The pattern we provide follows regular expression.
  • if our string is in default format (YYYY-MM-dd), we can convert to date object just in one step.
  • if you have your dates in a different format than the default one, you have to use DateTimeFormatter to provide your custom pattern.
  • YYYY pattern doesn’t work so we need to use uuuu for the year.


  • It’s similar to LocalDate, but it’s used only for a time(hours, minutes, seconds, and nanoseconds).
  • It is immutable as well.
  • that’s how we get the current time.


  • LocalDateTime can work dates and times as well.
  • The methods are really similar to LocalDate and LocalTime
  • After T time goes






Software Developer, Java Instructor

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

How to upload Database from your local to cpanel through terminal

Some HTML5 Secrets and Tricks I Learned During a Bootcamp

How to create a Python Package in Minutes

Port Swigger Lab-SQL injection vulnerability in WHERE clause allowing retrieval of hidden data

Let’s pay some attention to the man behind the curtain: the Land of SysAdmins.

Simple wildcard for Prometheus queries

Querying in ActiveRecord: Why SQL is still important

Merge Sort Explained

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store


Software Developer, Java Instructor

More from Medium

Unit Testing in Java

Java Maps- My toolbox

Streams in Java — Quick Guide with Examples

what is Garbage Collector, Stack ,Heap in JAVA?