java.time.ZonedDateTime Class


Advertisements


Introduction

The java.time.ZonedDateTime class represents a date-time with a time-zone in the ISO-8601 calendar system, such as 2007-12-03T10:15:30+01:00 Europe/Paris.

Class declaration

Following is the declaration for java.time.ZonedDateTime class −

public final class ZonedDateTime
   extends Object
      implements Temporal, ChronoZonedDateTime<LocalDate>, Serializable

Class methods

Sr.No. Method & Description
1 boolean equals(Object obj)

Checks if this date-time is equal to another date-time.

2 String format(DateTimeFormatter formatter)

Formats this date-time using the specified formatter.

3 static ZonedDateTime from(TemporalAccessor temporal)

Obtains an instance of ZonedDateTime from a temporal object.

4 int get(TemporalField field)

Gets the value of the specified field from this date-time as an int.

5 int getDayOfMonth()

Gets the day-of-month field.

6 DayOfWeek getDayOfWeek()

Gets the day-of-week field, which is an enum DayOfWeek.

7 int getDayOfYear()

Gets the day-of-year field.

8 int getHour()

Gets the hour-of-day field.

9 long getLong(TemporalField field)

Gets the value of the specified field from this date-time as a long.

10 Month getMinute()

Gets the minute-of-hour field.

11 Month getMonth()

Gets the month-of-year field using the Month enum.

12 int getMonthValue()

Gets the month-of-year field from 1 to 12.

13 int getNano()

Gets the nano-of-second field.

14 ZoneOffset getOffset()

Gets the zone offset, such as '+01:00'.

15 int getSecond()

Gets the second-of-minute field.

16 int getYear()

Gets the year field.

17 ZoneId getZone()

Gets the time-zone, such as 'Europe/Paris'.

18 int hashCode()

A hash code for this date-time.

19 boolean isSupported(TemporalField field)

Checks if the specified field is supported.

20 boolean isSupported(TemporalUnit unit)

Checks if the specified unit is supported.

21 ZonedDateTime minus(long amountToSubtract, TemporalUnit unit)

Returns a copy of this date-time with the specified amount subtracted.

22 ZonedDateTime minus(TemporalAmount amountToSubtract)

Returns a copy of this date-time with the specified amount subtracted.

23 ZonedDateTime minusDays(long daysToSubtract)

Returns a copy of this ZonedDateTime with the specified number of days subtracted.

24 ZonedDateTime minusHours(long hoursToSubtract)

Returns a copy of this ZonedDateTime with the specified number of hours subtracted.

25 ZonedDateTime minusMinutes(long minutesToSubtract)

Returns a copy of this ZonedDateTime with the specified number of minutes subtracted.

26 ZonedDateTime minusMonths(long monthsToSubtract)

Returns a copy of this ZonedDateTime with the specified number of months subtracted.

27 ZonedDateTime minusNanos(long nanos)

Returns a copy of this ZonedDateTime with the specified number of nanoseconds subtracted.

28 ZonedDateTime minusSeconds(long seconds)

Returns a copy of this ZonedDateTime with the specified number of seconds subtracted.

29 ZonedDateTime minusWeeks(long weeksToSubtract)

Returns a copy of this ZonedDateTime with the specified number of weeks subtracted.

30 ZonedDateTime minusYears(long yearsToSubtract)

Returns a copy of this ZonedDateTime with the specified number of years subtracted.

31 static ZonedDateTime now()

Obtains the current date-time from the system clock in the default time-zone.

32 static ZonedDateTime now(Clock clock)

Obtains the current date-time from the specified clock.

33 static ZonedDateTime now(ZoneId zone)

Obtains the current date-time from the system clock in the specified time-zone.

34 static ZonedDateTime of(int year, int month, int dayOfMonth, int hour, int minute, int second, int nanoOfSecond, ZoneId zone)

Obtains an instance of ZonedDateTime from year, month, day, hour, minute, second, nanosecond and time-zone.

35 static ZonedDateTime of(LocalDate date, LocalTime time, ZoneId zone)

Obtains an instance of ZonedDateTime from a date and time.

36 static ZonedDateTime of(LocalDateTime date, ZoneId zone)

Obtains an instance of ZonedDateTime from a local date-time.

37 static ZonedDateTime ofInstant(Instant instant, ZoneId zone)

Obtains an instance of ZonedDateTime from an Instant and zone ID.

38 static ZonedDateTime ofInstant(LocalDateTime localDateTime, ZoneOffset offset, ZoneId zone)

Obtains an instance of ZonedDateTime from the instant formed by combining the local date-time and offset.

39 static ZonedDateTime ofLocal(LocalDateTime localDateTime, ZoneId zone, ZoneOffset preferredOffset)

Obtains an instance of ZonedDateTime from a local date-time using the preferred offset if possible.

40 static ZonedDateTime ofStrict(LocalDateTime localDateTime, ZoneOffset offset, ZoneId zone)

Obtains an instance of ZonedDateTime strictly validating the combination of local date-time, offset and zone ID.

41 static ZonedDateTime parse(CharSequence text)

Obtains an instance of ZonedDateTime from a text string such as 2007-12-03T10:15:30+01:00[Europe/Paris].

42 static ZonedDateTime parse(CharSequence text, DateTimeFormatter formatter)

Obtains an instance of ZonedDateTime from a text string using a specific formatter.

43 ZonedDateTime plus(long amountToAdd, TemporalUnit unit)

Returns a copy of this date-time with the specified amount added.

44 ZonedDateTime plus(TemporalAmount amountToAdd)

Returns a copy of this date-time with the specified amount added.

45 ZonedDateTime plusDays(long daysToAdd)

Returns a copy of this ZonedDateTime with the specified number of days added.

46 ZonedDateTime plusHours(long hoursToAdd)

Returns a copy of this ZonedDateTime with the specified number of hours added.

47 ZonedDateTime plusMinutes(long minutesToAdd)

Returns a copy of this ZonedDateTime with the specified number of minutes added.

48 ZonedDateTime plusMonths(long monthsToAdd)

Returns a copy of this ZonedDateTime with the specified number of months added.

49 ZonedDateTime plusNanos(long nanos)

Returns a copy of this ZonedDateTime with the specified number of nanoseconds added.

50 ZonedDateTime plusSeconds(long seconds)

Returns a copy of this ZonedDateTime with the specified number of seconds added.

51 ZonedDateTime plusWeeks(long weeksToAdd)

Returns a copy of this ZonedDateTime with the specified number of weeks added.

52 ZonedDateTime plusYears(long yearsToAdd)

Returns a copy of this ZonedDateTime with the specified number of years added.

53 <R> R query(TemporalQuery<R> query)

Queries this date-time using the specified query.

54 ValueRange range(TemporalField field)

Gets the range of valid values for the specified field.

55 LocalDate toLocalDate()

Gets the LocalDate part of this date-time.

56 LocalTime toLocalTime()

Gets the LocalTime part of this date-time.

57 OffsetDateTime toOffsetDateTime()

Converts this date-time to an OffsetDateTime.

58 String toString()

Outputs this date as a String, such as 2007-12-03T10:15:30+01:00[Europe/Paris].

59 ZonedDateTime truncatedTo(TemporalUnit unit)

Returns a copy of this ZonedDateTime with the time truncated.

60 long until(Temporal endExclusive, TemporalUnit unit)

Calculates the amount of time until another date-time in terms of the specified unit.

61 ZonedDateTime with(TemporalAdjuster adjuster)

Returns an adjusted copy of this date-time.

62 ZonedDateTime with(TemporalField field, long newValue)

Returns a copy of this date-time with the specified field set to a new value.

63 ZonedDateTime withDayOfMonth(int dayOfMonth)

Returns a copy of this ZonedDateTime with the day-of-month altered.

64 ZonedDateTime withDayOfYear(int dayOfYear)

Returns a copy of this ZonedDateTime with the day-of-year altered.

65 ZonedDateTime withEarlierOffsetAtOverlap()

Returns a copy of this date-time changing the zone offset to the earlier of the two valid offsets at a local time-line overlap.

66 ZonedDateTime withFixedOffsetZone()

Returns a copy of this date-time with the zone ID set to the offset.

67 ZonedDateTime withHour(int hour)

Returns a copy of this ZonedDateTime with the hour-of-day altered.

68 ZonedDateTime withLaterOffsetAtOverlap()

Returns a copy of this date-time changing the zone offset to the later of the two valid offsets at a local time-line overlap.

69 ZonedDateTime withMinute(int minute)

Returns a copy of this ZonedDateTime with the minute-of-hour altered.

70 ZonedDateTime withMonth(int month)

Returns a copy of this ZonedDateTime with the month-of-year altered.

71 ZonedDateTime withNano(int nanoOfSecond)

Returns a copy of this ZonedDateTime with the nano-of-second altered.

72 ZonedDateTime withSecond(int second)

Returns a copy of this ZonedDateTime with the second-of-minute altered.

73 ZonedDateTime withYear(int year)

Returns a copy of this ZonedDateTime with the year altered.

74 ZonedDateTime withZoneSameInstant(ZoneId zone)

Returns a copy of this date-time with a different time-zone, retaining the instant.

75 ZonedDateTime withZoneSameLocal(ZoneId zone)

Returns a copy of this date-time with a different time-zone, retaining the local date-time if possible.

Methods inherited

This class inherits methods from the following classes −

  • Java.lang.Object


Advertisements
E-Books Store