Java LocalDateTime Methods

Beginner
6 min read
Updated: Nov 2026
62 method guides
Method index

About This Index

This page is the Java LocalDateTime Methods index. Each row links to a full guide with syntax, parameters, return value, three runnable examples, and FAQs. Every example is a complete Java class with a main method and fixed data, and all of them compile on Java 8 and later.

New to LocalDateTime? It holds a date and a time, such as 2026-03-15T10:30, with no time zone. It comes from the java.time package, so you write import java.time.LocalDateTime; first. You create one with now(), of(), or parse(), and read it with methods such as getYear(). It keeps time down to the nanosecond. It is immutable, so plusDays() and withHour() return a new object, and the old one never changes.

Keep the result

Writing dt.plusDays(1); on its own does nothing, because the new date-time is thrown away. Always store it: dt = dt.plusDays(1);. Also remember that months are numbered from 1 (January) to 12, and that a LocalDateTime has no zone, so it is not an exact moment on the timeline. To get one, use atZone() or atOffset().

How to Call a LocalDateTime Method

Create a LocalDateTime, then call each method on the variable and keep the result:

Java
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

LocalDateTime start = LocalDateTime.of(2026, 3, 15, 10, 30);  // 2026-03-15T10:30
LocalDateTime later = start.plusDays(2).plusHours(3);         // 2026-03-17T13:30

boolean after = later.isAfter(start);                         // true
int year = start.getYear();                                   // 2026
String text = later.format(DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm"));  // "17/03/2026 13:30"
System.out.println(start);                                    // 2026-03-15T10:30, unchanged

Java LocalDateTime Methods Table

All method guides in this Java tutorial series (62 tutorials), grouped by purpose.

Create a date-time

6 methods

Get the current date and time, build one from numbers, read one from text, or convert it from an epoch time, an Instant, or another date-time object.

MethodDescriptionTutorial
now()Get the current date and time from the system clock.Try it
of()Build a date-time from the year, month, day, hour, and minute.Try it
parse()Read a date-time from text.Try it
ofEpochSecond()Build a date-time from seconds counted since 1970.Try it
ofInstant()Convert an Instant into the date-time of a time zone.Try it
from()Convert another date-time object into a LocalDateTime.Try it

Read the parts

10 methods

Get the year, the month, the day, the weekday, the hour, the minute, the second, or the nanosecond as a plain number or an enum.

MethodDescriptionTutorial
getYear()Read the year as a number.Try it
getMonth()Read the month as a Month enum such as MARCH.Try it
getMonthValue()Read the month as a number from 1 to 12.Try it
getDayOfMonth()Read the day of the month, from 1 to 31.Try it
getDayOfWeek()Read the weekday as a DayOfWeek enum such as SUNDAY.Try it
getDayOfYear()Read the day number inside the year, from 1 to 366.Try it
getHour()Read the hour on a 24-hour clock, from 0 to 23.Try it
getMinute()Read the minute of the hour, from 0 to 59.Try it
getSecond()Read the second of the minute, from 0 to 59.Try it
getNano()Read the fraction of the second, in nanoseconds.Try it

Add time

9 methods

Move a date-time forward by days, weeks, months, years, hours, minutes, seconds, or nanoseconds. Each method returns a new object.

MethodDescriptionTutorial
plus()Add an amount in any unit, or add a Duration or a Period.Try it
plusDays()Return a copy that is a number of days later.Try it
plusWeeks()Return a copy that is a number of weeks later.Try it
plusMonths()Return a copy that is a number of months later.Try it
plusYears()Return a copy that is a number of years later.Try it
plusHours()Return a copy that is a number of hours later.Try it
plusMinutes()Return a copy that is a number of minutes later.Try it
plusSeconds()Return a copy that is a number of seconds later.Try it
plusNanos()Return a copy that is a number of nanoseconds later.Try it

Subtract time

9 methods

Move a date-time backward by any unit. These are the mirror images of the plus methods, and they follow the same end-of-month rules.

MethodDescriptionTutorial
minus()Subtract an amount in any unit, or subtract a Duration or a Period.Try it
minusDays()Return a copy that is a number of days earlier.Try it
minusWeeks()Return a copy that is a number of weeks earlier.Try it
minusMonths()Return a copy that is a number of months earlier.Try it
minusYears()Return a copy that is a number of years earlier.Try it
minusHours()Return a copy that is a number of hours earlier.Try it
minusMinutes()Return a copy that is a number of minutes earlier.Try it
minusSeconds()Return a copy that is a number of seconds earlier.Try it
minusNanos()Return a copy that is a number of nanoseconds earlier.Try it

Change one part

10 methods

Replace a single part, such as the year, the month, the day, or the hour, or cut the small parts of the time away with truncatedTo().

MethodDescriptionTutorial
with()Return a copy changed by an adjuster, or with one field replaced.Try it
withYear()Return a copy with a different year.Try it
withMonth()Return a copy with a different month.Try it
withDayOfMonth()Return a copy with a different day of the month.Try it
withDayOfYear()Return a copy with a different day of the year.Try it
withHour()Return a copy with a different hour.Try it
withMinute()Return a copy with a different minute.Try it
withSecond()Return a copy with a different second.Try it
withNano()Return a copy with a different fraction of a second.Try it
truncatedTo()Cut off the parts of the time that are smaller than a unit.Try it

Compare and measure

7 methods

Find out which date-time is earlier, check if two are equal, sort them, use them as keys, and count the complete days or hours between them.

MethodDescriptionTutorial
isBefore()Check if this date-time is earlier than another.Try it
isAfter()Check if this date-time is later than another.Try it
isEqual()Check if two date-times are at the same moment on the local timeline.Try it
equals()Check if two objects are the same date and time.Try it
compareTo()Compare two date-times and get a negative, zero, or positive number.Try it
hashCode()Get a number that goes with equals, for use in hash-based collections.Try it
until()Count the complete units between two date-times.Try it

Format and convert

6 methods

Turn a date-time into text, or split it into a date and a time. Add an offset or a time zone to get a real moment on the timeline.

MethodDescriptionTutorial
format()Turn a date-time into text using a pattern you choose.Try it
toString()Get the date-time as ISO-8601 text such as 2026-03-15T10:30.Try it
toLocalDate()Get only the date part, without the time.Try it
toLocalTime()Get only the time of day, without the date.Try it
atOffset()Attach a fixed offset from UTC, such as +05:30, to a date-time.Try it
atZone()Attach a time zone to a date-time and get a ZonedDateTime.Try it

Fields and queries

5 methods

The general methods that work with any field: ask for a field by name, test what is supported, find the allowed range, or run a query.

MethodDescriptionTutorial
get()Read any field of the date-time as an int.Try it
getLong()Read any field of the date-time as a long.Try it
isSupported()Check if a field or a unit can be used with this date-time.Try it
range()Get the valid range of values of a field for this date-time.Try it
query()Run a query on the date-time and get a result of any type.Try it

Frequently Asked Questions

They are the methods of java.time.LocalDateTime, a date and a time without a time zone, such as 2026-03-15T10:30. They create a date-time, read its parts, add or subtract time, change one part, compare two date-times, and format or convert them.
This index lists 62 guides, grouped by what they do. Start with now(), of(), and getYear(). Then try plusDays(), isBefore(), and format() to see how a date-time is moved, compared, and printed.
Use LocalDateTime for a date and time on a wall clock, such as an appointment or a school timetable, where the zone does not matter or is stored elsewhere. Use ZonedDateTime or Instant when you need the exact moment on the timeline.
LocalDateTime is immutable. Every plus, minus, and with method returns a new object and leaves the original as it was. Keep the result, for example: dt = dt.plusDays(1).
LocalDateTime was added in Java 8, in the java.time package. Every method in this series is available from Java 8 on, and every example compiles on Java 8 and later.

Start with now()

Read the current date and time from the clock, the first thing most programs do with dates.

now() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

12 people found this page helpful