LocalDateTime is an immutable date-time object that represents a date-time, often viewed as year-month-day-hour-minute-second. Other date and time fields, such as day-of-year, day-of-week and week-of-year, can also be accessed. Time is represented to nanosecond precision. For example, the value "2nd October 2007 at 13:45.30.123456789" can be stored in a LocalDateTime. This class does not store or represent a time-zone. Instead, it is a description of the date, as used for birthdays, combined with the local time as seen on a wall clock. It cannot represent an instant on the time-line without additional information such as an offset or time-zone. The ISO-8601 calendar system is the modern civil calendar system used today in most of the world. It is equivalent to the proleptic Gregorian calendar system, in which today's rules for leap years are applied for all time. For most applications written today, the ISO-8601 rules are entirely suitable. However, any application that makes use of historical dates, and requires them to be accurate will find the ISO-8601 approach unsuitable. This is a value-based class; use of identity-sensitive operations (including reference equality (==), identity hash code, or synchronization) on instances of LocalDateTime may have unpredictable results and should be avoided. The equals method should be used for comparisons.Implementation Requirements:This class is immutable and thread-safe.Since:1.8See Also:Serialized FormField SummaryFields Modifier and TypeField and Descriptionstatic LocalDateTimeMAXThe maximum supported LocalDateTime, '+999999999-12-31T23:59:59.999999999'.static LocalDateTimeMINThe minimum supported LocalDateTime, '-999999999-01-01T00:00:00'.Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and TypeMethod and DescriptionTemporaladjustInto(Temporal temporal)Adjusts the specified temporal object to have the same date and time as this object.OffsetDateTimeatOffset(ZoneOffset offset)Combines this date-time with an offset to create an OffsetDateTime.ZonedDateTimeatZone(ZoneId zone)Combines this date-time with a time-zone to create a ZonedDateTime.intcompareTo(ChronoLocalDateTime other)Compares this date-time to another date-time.booleanequals(Object obj)Checks if this date-time is equal to another date-time.Stringformat(DateTimeFormatter formatter)Formats this date-time using the specified formatter.static LocalDateTimefrom(TemporalAccessor temporal)Obtains an instance of LocalDateTime from a temporal object.intget(TemporalField field)Gets the value of the specified field from this date-time as an int.intgetDayOfMonth()Gets the day-of-month field.DayOfWeekgetDayOfWeek()Gets the day-of-week field, which is an enum DayOfWeek.intgetDayOfYear()Gets the day-of-year field.intgetHour()Gets the hour-of-day field.longgetLong(TemporalField field)Gets the value of the specified field from this date-time as a long.intgetMinute()Gets the minute-of-hour field.MonthgetMonth()Gets the month-of-year field using the Month enum.intgetMonthValue()Gets the month-of-year field from 1 to 12.intgetNano()Gets the nano-of-second field.intgetSecond()Gets the second-of-minute field.intgetYear()Gets the year field.inthashCode()A hash code for this date-time.booleanisAfter(ChronoLocalDateTime other)Checks if this date-time is after the specified date-time.booleanisBefore(ChronoLocalDateTime other)Checks if this date-time is before the specified date-time.booleanisEqual(ChronoLocalDateTime other)Checks if this date-time is equal to the specified date-time.booleanisSupported(TemporalField field)Checks if the specified field is supported.booleanisSupported(TemporalUnit unit)Checks if the specified unit is supported.LocalDateTimeminus(long amountToSubtract, TemporalUnit unit)Returns a copy of this date-time with the specified amount subtracted.LocalDateTimeminus(TemporalAmount amountToSubtract)Returns a copy of this date-time with the specified amount subtracted.LocalDateTimeminusDays(long days)Returns a copy of this LocalDateTime with the specified number of days subtracted.LocalDateTimeminusHours(long hours)Returns a copy of this LocalDateTime with the specified number of hours subtracted.LocalDateTimeminusMinutes(long minutes)Returns a copy of this LocalDateTime with the specified number of minutes subtracted.LocalDateTimeminusMonths(long months)Returns a copy of this LocalDateTime with the specified number of months subtracted.LocalDateTimeminusNanos(long nanos)Returns a copy of this LocalDateTime with the specified number of nanoseconds subtracted.LocalDateTimeminusSeconds(long seconds)Returns a copy of this LocalDateTime with the specified number of seconds subtracted.LocalDateTimeminusWeeks(long weeks)Returns a copy of this LocalDateTime with the specified number of weeks subtracted.LocalDateTimeminusYears(long years)Returns a copy of this LocalDateTime with the specified number of years subtracted.static LocalDateTimenow()Obtains the current date-time from the system clock in the default time-zone.static LocalDateTimenow(Clock clock)Obtains the current date-time from the specified clock.static LocalDateTimenow(ZoneId zone)Obtains the current date-time from the system clock in the specified time-zone.static LocalDateTimeof(int year, int month, int dayOfMonth, int hour, int minute)Obtains an instance of LocalDateTime from year, month, day, hour and minute, setting the second and nanosecond to zero.static LocalDateTimeof(int year, int month, int dayOfMonth, int hour, int minute, int second)Obtains an instance of LocalDateTime from year, month, day, hour, minute and second, setting the nanosecond to zero.static LocalDateTimeof(int year, int month, int dayOfMonth, int hour, int minute, int second, int nanoOfSecond)Obtains an instance of LocalDateTime from year, month, day, hour, minute, second and nanosecond.static LocalDateTimeof(int year, Month month, int dayOfMonth, int hour, int minute)Obtains an instance of LocalDateTime from year, month, day, hour and minute, setting the second and nanosecond to zero.static LocalDateTimeof(int year, Month month, int dayOfMonth, int hour, int minute, int second)Obtains an instance of LocalDateTime from year, month, day, hour, minute and second, setting the nanosecond to zero.static LocalDateTimeof(int year, Month month, int dayOfMonth, int hour, int minute, int second, int nanoOfSecond)Obtains an instance of LocalDateTime from year, month, day, hour, minute, second and nanosecond.static LocalDateTimeof(LocalDate date, LocalTime time)Obtains an instance of LocalDateTime from a date and time.static LocalDateTimeofEpochSecond(long epochSecond, int nanoOfSecond, ZoneOffset offset)Obtains an instance of LocalDateTime using seconds from the epoch of 1970-01-01T00:00:00Z.static LocalDateTimeofInstant(Instant instant, ZoneId zone)Obtains an instance of LocalDateTime from an Instant and zone ID.static LocalDateTimeparse(CharSequence text)Obtains an instance of LocalDateTime from a text string such as 2007-12-03T10:15:30.static LocalDateTimeparse(CharSequence text, DateTimeFormatter formatter)Obtains an instance of LocalDateTime from a text string using a specific formatter.LocalDateTimeplus(long amountToAdd, TemporalUnit unit)Returns a copy of this date-time with the specified amount added.LocalDateTimeplus(TemporalAmount amountToAdd)Returns a copy of this date-time with the specified amount added.LocalDateTimeplusDays(long days)Returns a copy of this LocalDateTime with the specified number of days added.LocalDateTimeplusHours(long hours)Returns a copy of this LocalDateTime with the specified number of hours added.LocalDateTimeplusMinutes(long minutes)Returns a copy of this LocalDateTime with the specified number of minutes added.LocalDateTimeplusMonths(long months)Returns a copy of this LocalDateTime with the specified number of months added.LocalDateTimeplusNanos(long nanos)Returns a copy of this LocalDateTime with the specified number of nanoseconds added.LocalDateTimeplusSeconds(long seconds)Returns a copy of this LocalDateTime with the specified number of seconds added.LocalDateTimeplusWeeks(long weeks)Returns a copy of this LocalDateTime with the specified number of weeks added.LocalDateTimeplusYears(long years)Returns a copy of this LocalDateTime with the specified number of years added. Rquery(TemporalQuery query)Queries this date-time using the specified query.ValueRangerange(TemporalField field)Gets the range of valid values for the specified field.LocalDatetoLocalDate()Gets the LocalDate part of this date-time.LocalTimetoLocalTime()Gets the LocalTime part of this date-time.StringtoString()Outputs this date-time as a String, such as 2007-12-03T10:15:30.LocalDateTimetruncatedTo(TemporalUnit unit)Returns a copy of this LocalDateTime with the time truncated.longuntil(Temporal endExclusive, TemporalUnit unit)Calculates the amount of time until another date-time in terms of the specified unit.LocalDateTimewith(TemporalAdjuster adjuster)Returns an adjusted copy of this date-time.LocalDateTimewith(TemporalField field, long newValue)Returns a copy of this date-time with the specified field set to a new value.LocalDateTimewithDayOfMonth(int dayOfMonth)Returns a copy of this LocalDateTime with the day-of-month altered.LocalDateTimewithDayOfYear(int dayOfYear)Returns a copy of this LocalDateTime with the day-of-year altered.LocalDateTimewithHour(int hour)Returns a copy of this LocalDateTime with the hour-of-day altered.LocalDateTimewithMinute(int minute)Returns a copy of this LocalDateTime with the minute-of-hour altered.LocalDateTimewithMonth(int month)Returns a copy of this LocalDateTime with the month-of-year altered.LocalDateTimewithNano(int nanoOfSecond)Returns a copy of this LocalDateTime with the nano-of-second altered.LocalDateTimewithSecond(int second)Returns a copy of this LocalDateTime with the second-of-minute altered.LocalDateTimewithYear(int year)Returns a copy of this LocalDateTime with the year altered.Methods inherited from class java.lang.Objectclone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.time.chrono.ChronoLocalDateTimegetChronology, timeLineOrder, toEpochSecond, toInstantField DetailMINpublic static final LocalDateTime MINThe minimum supported LocalDateTime, '-999999999-01-01T00:00:00'. This is the local date-time of midnight at the start of the minimum date. This combines LocalDate.MIN and LocalTime.MIN. This could be used by an application as a "far past" date-time.MAXpublic static final LocalDateTime MAXThe maximum supported LocalDateTime, '+999999999-12-31T23:59:59.999999999'. This is the local date-time just before midnight at the end of the maximum date. This combines LocalDate.MAX and LocalTime.MAX. This could be used by an application as a "far future" date-time.Method Detailnowpublic static LocalDateTime now()Obtains the current date-time from the system clock in the default time-zone. This will query the system clock in the default time-zone to obtain the current date-time. Using this method will prevent the ability to use an alternate clock for testing because the clock is hard-coded.Returns:the current date-time using the system clock and default time-zone, not nullnowpublic static LocalDateTime now(ZoneId zone)Obtains the current date-time from the system clock in the specified time-zone. This will query the system clock to obtain the current date-time. Specifying the time-zone avoids dependence on the default time-zone. Using this method will prevent the ability to use an alternate clock for testing because the clock is hard-coded.Parameters:zone - the zone ID to use, not nullReturns:the current date-time using the system clock, not nullnowpublic static LocalDateTime now(Clock clock)Obtains the current date-time from the specified clock. This will query the specified clock to obtain the current date-time. Using this method allows the use of an alternate clock for testing. The alternate clock may be introduced using dependency injection.Parameters:clock - the clock to use, not nullReturns:the current date-time, not nullofpublic static LocalDateTime of(int year, Month month, int dayOfMonth, int hour, int minute)Obtains an instance of LocalDateTime from year, month, day, hour and minute, setting the second and nanosecond to zero. This returns a LocalDateTime with the specified year, month, day-of-month, hour and minute. The day must be valid for the year and month, otherwise an exception will be thrown. The second and nanosecond fields will be set to zero.Parameters:year - the year to represent, from MIN_YEAR to MAX_YEARmonth - the month-of-year to represent, not nulldayOfMonth - the day-of-month to represent, from 1 to 31hour - the hour-of-day to represent, from 0 to 23minute - the minute-of-hour to represent, from 0 to 59Returns:the local date-time, not nullThrows:DateTimeException - if the value of any field is out of range, or if the day-of-month is invalid for the month-yearofpublic static LocalDateTime of(int year, Month month, int dayOfMonth, int hour, int minute, int second)Obtains an instance of LocalDateTime from year, month, day, hour, minute and second, setting the nanosecond to zero. This returns a LocalDateTime with the specified year, month, day-of-month, hour, minute and second. The day must be valid for the year and month, otherwise an exception will be thrown. The nanosecond field will be set to zero.Parameters:year - the year to represent, from MIN_YEAR to MAX_YEARmonth - the month-of-year to represent, not nulldayOfMonth - the day-of-month to represent, from 1 to 31hour - the hour-of-day to represent, from 0 to 23minute - the minute-of-hour to represent, from 0 to 59second - the second-of-minute to represent, from 0 to 59Returns:the local date-time, not nullThrows:DateTimeException - if the value of any field is out of range, or if the day-of-month is invalid for the month-yearofpublic static LocalDateTime of(int year, Month month, int dayOfMonth, int hour, int minute, int second, int nanoOfSecond)Obtains an instance of LocalDateTime from year, month, day, hour, minute, second and nanosecond. This returns a LocalDateTime with the specified year, month, day-of-month, hour, minute, second and nanosecond. The day must be valid for the year and month, otherwise an exception will be thrown.Parameters:year - the year to represent, from MIN_YEAR to MAX_YEARmonth - the month-of-year to represent, not nulldayOfMonth - the day-of-month to represent, from 1 to 31hour - the hour-of-day to represent, from 0 to 23minute - the minute-of-hour to represent, from 0 to 59second - the second-of-minute to represent, from 0 to 59nanoOfSecond - the nano-of-second to represent, from 0 to 999,999,999Returns:the local date-time, not nullThrows:DateTimeException - if the value of any field is out of range, or if the day-of-month is invalid for the month-yearofpublic static LocalDateTime of(int year, int month, int dayOfMonth, int hour, int minute)Obtains an instance of LocalDateTime from year, month, day, hour and minute, setting the second and nanosecond to zero. This returns a LocalDateTime with the specified year, month, day-of-month, hour and minute. The day must be valid for the year and month, otherwise an exception will be thrown. The second and nanosecond fields will be set to zero.Parameters:year - the year to represent, from MIN_YEAR to MAX_YEARmonth - the month-of-year to represent, from 1 (January) to 12 (December)dayOfMonth - the day-of-month to represent, from 1 to 31hour - the hour-of-day to represent, from 0 to 23minute - the minute-of-hour to represent, from 0 to 59Returns:the local date-time, not nullThrows:DateTimeException - if the value of any field is out of range, or if the day-of-month is invalid for the month-yearofpublic static LocalDateTime of(int year, int month, int dayOfMonth, int hour, int minute, int second)Obtains an instance of LocalDateTime from year, month, day, hour, minute and second, setting the nanosecond to zero. This returns a LocalDateTime with the specified year, month, day-of-month, hour, minute and second. The day must be valid for the year and month, otherwise an exception will be thrown. The nanosecond field will be set to zero.Parameters:year - the year to represent, from MIN_YEAR to MAX_YEARmonth - the month-of-year to represent, from 1 (January) to 12 (December)dayOfMonth - the day-of-month to represent, from 1 to 31hour - the hour-of-day to represent, from 0 to 23minute - the minute-of-hour to represent, from 0 to 59second - the second-of-minute to represent, from 0 to 59Returns:the local date-time, not nullThrows:DateTimeException - if the value of any field is out of range, or if the day-of-month is invalid for the month-yearofpublic static LocalDateTime of(int year, int month, int dayOfMonth, int hour, int minute, int second, int nanoOfSecond)Obtains an instance of LocalDateTime from year, month, day, hour, minute, second and nanosecond. This returns a LocalDateTime with the specified year, month, day-of-month, hour, minute, second and nanosecond. The day must be valid for the year and month, otherwise an exception will be thrown.Parameters:year - the year to represent, from MIN_YEAR to MAX_YEARmonth - the month-of-year to represent, from 1 (January) to 12 (December)dayOfMonth - the day-of-month to represent, from 1 to 31hour - the hour-of-day to represent, from 0 to 23minute - the minute-of-hour to represent, from 0 to 59second - the second-of-minute to represent, from 0 to 59nanoOfSecond - the nano-of-second to represent, from 0 to 999,999,999Returns:the local date-time, not nullThrows:DateTimeException - if the value of any field is out of range, or if the day-of-month is invalid for the month-yearofpublic static LocalDateTime of(LocalDate date, LocalTime time)Obtains an instance of LocalDateTime from a date and time.Parameters:date - the local date, not nulltime - the local time, not nullReturns:the local date-time, not nullofInstantpublic static LocalDateTime ofInstant(Instant instant, ZoneId zone)Obtains an instance of LocalDateTime from an Instant and zone ID. This creates a local date-time based on the specified instant. First, the offset from UTC/Greenwich is obtained using the zone ID and instant, which is simple as there is only one valid offset for each instant. Then, the instant and offset are used to calculate the local date-time.Parameters:instant - the instant to create the date-time from, not nullzone - the time-zone, which may be an offset, not nullReturns:the local date-time, not nullThrows:DateTimeException - if the result exceeds the supported rangeofEpochSecondpublic static LocalDateTime ofEpochSecond(long epochSecond, int nanoOfSecond, ZoneOffset offset)Obtains an instance of LocalDateTime using seconds from the epoch of 1970-01-01T00:00:00Z. This allows the epoch-second field to be converted to a local date-time. This is primarily intended for low-level conversions rather than general application usage.Parameters:epochSecond - the number of seconds from the epoch of 1970-01-01T00:00:00ZnanoOfSecond - the nanosecond within the second, from 0 to 999,999,999offset - the zone offset, not nullReturns:the local date-time, not nullThrows:DateTimeException - if the result exceeds the supported range, or if the nano-of-second is invalidfrompublic static LocalDateTime from(TemporalAccessor temporal)Obtains an instance of LocalDateTime from a temporal object. This obtains a local date-time based on the specified temporal. A TemporalAccessor represents an arbitrary set of date and time information, which this factory converts to an instance of LocalDateTime. The conversion extracts and combines the LocalDate and the LocalTime from the temporal object. Implementations are permitted to perform optimizations such as accessing those fields that are equivalent to the relevant objects. This method matches the signature of the functional interface TemporalQuery allowing it to be used as a query via method reference, LocalDateTime::from.Specified by:from in interface ChronoLocalDateTimeParameters:temporal - the temporal object to convert, not nullReturns:the local date-time, not nullThrows:DateTimeException - if unable to convert to a LocalDateTimeSee Also:Chronology.localDateTime(TemporalAccessor)parsepublic static LocalDateTime parse(CharSequence text)Obtains an instance of LocalDateTime from a text string such as 2007-12-03T10:15:30. The string must represent a valid date-time and is parsed using DateTimeFormatter.ISO_LOCAL_DATE_TIME.Parameters:text - the text to parse such as "2007-12-03T10:15:30", not nullReturns:the parsed local date-time, not nullThrows:DateTimeParseException - if the text cannot be parsedparsepublic static LocalDateTime parse(CharSequence text, DateTimeFormatter formatter)Obtains an instance of LocalDateTime from a text string using a specific formatter. The text is parsed using the formatter, returning a date-time.Parameters:text - the text to parse, not nullformatter - the formatter to use, not nullReturns:the parsed local date-time, not nullThrows:DateTimeParseException - if the text cannot be parsedisSupportedpublic boolean isSupported(TemporalField field)Checks if the specified field is supported. This checks if this date-time can be queried for the specified field. If false, then calling the range, get and with(TemporalField, long) methods will throw an exception. If the field is a ChronoField then the query is implemented here. The supported fields are: