java.time.ZonedDateTime Class ”; Previous Next 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.
Category: javatime
java.time – LocalTime
java.time.LocalTime Class ”; Previous Next Introduction The java.time.LocalTime class represents a time without a time-zone in the ISO-8601 calendar system, such as 10:15:30. Class declaration Following is the declaration for java.time.LocalTime class − public final class LocalTime extends Object implements Temporal, TemporalAdjuster, Comparable<LocalDate>, Serializable Field Following are the fields for java.time.LocalTime class − static LocalTime MAX − The maximum supported LocalTime, ”23:59:59.999999999”. static LocalTime MIN − The minimum supported LocalTime, ”00:00”. static LocalTime MIDNIGHT − The time of midnight at the start of the day, ”00:00”. static LocalTime NOON − The time of noon in the middle of the day, ”12:00”. Class methods Sr.No. Method & Description 1 Temporal adjustInto(Temporal temporal) Adjusts the specified temporal object to have the same date and time as this object. 2 LocalDateTime atDate(LocalDate date) Combines this time with a date to create a LocalDateTime. 3 OffsetDateTime atOffset(ZoneOffset offset) Combines this time with an offset time to create an OffsetDateTime. 4 int compareTo(LocalTime other) Compares this time to another time. 5 boolean equals(Object obj) Checks if this time is equal to another time. 6 String format(DateTimeFormatter formatter) Formats this time using the specified formatter. 7 static LocalTime from(TemporalAccessor temporal) Obtains an instance of LocalTime from a temporal object. 8 int get(TemporalField field) Gets the value of the specified field from this time as an int. 9 int getHour() Gets the hour-of-day field. 10 long getLong(TemporalField field) Gets the value of the specified field from this time as a long. 11 int getMinute() Gets the minute-of-hour field. 12 int getNano() Gets the nano-of-second field. 13 int getSecond() Gets the second-of-minute field. 14 int hashCode() A hash code for this time. 15 boolean isAfter(LocalTime other) Checks if this time is after the specified time. 16 boolean isBefore(LocalTime other) Checks if this time is before the specified time. 17 boolean isSupported(TemporalField field) Checks if the specified field is supported. 18 boolean isSupported(TemporalUnit unit) Checks if the specified unit is supported. 19 LocalTime minus(long amountToSubtract, TemporalUnit unit) Returns a copy of this time with the specified amount subtracted. 20 LocalTime minus(TemporalAmount amountToSubtract) Returns a copy of this time with the specified amount subtracted. 21 LocalTime minusHours(long hoursToSubtract) Returns a copy of this LocalTime with the specified number of hours subtracted. 22 LocalTime minusMinutes(long minutesToSubtract) Returns a copy of this LocalTime with the specified number of minutes subtracted. 23 LocalTime minusNanos(long nanos) Returns a copy of this LocalTime with the specified number of nanoseconds subtracted. 24 LocalTime minusSeconds(long seconds) Returns a copy of this LocalTime with the specified number of seconds subtracted. 25 static LocalTime now() Obtains the current time from the system clock in the default time-zone. 26 static LocalTime now(Clock clock) Obtains the current time from the specified clock. 27 static LocalTime now(ZoneId zone) Obtains the current time from the system clock in the specified time-zone. 28 static LocalTime of(int hour, int minute) Obtains an instance of LocalTime from an hour and minute. 29 static LocalTime of(int hour, int minute, int second) Obtains an instance of LocalTime from an hour, minute and second. 30 static LocalTime of(int hour, int minute, int second, int nanoOfSecond) Obtains an instance of LocalTime from an hour, minute, second and nanosecond. 31 static LocalTime ofNanoOfDay(long nanoOfDay) Obtains an instance of LocalTime from a nanos-of-day value. 32 static LocalTime ofSecondOfDay(long secondOfDay) Obtains an instance of LocalTime from a second-of-day value. 33 static LocalTime parse(CharSequence text) Obtains an instance of LocalTime from a text string such as 2007-12-03T10:15:30. 34 static LocalTime parse(CharSequence text, DateTimeFormatter formatter) Obtains an instance of LocalTime from a text string using a specific formatter. 35 LocalTime plus(long amountToAdd, TemporalUnit unit) Returns a copy of this time with the specified amount added. 36 LocalTime plus(TemporalAmount amountToAdd) Returns a copy of this time with the specified amount added. 37 LocalTime plusHours(long hoursToAdd) Returns a copy of this LocalTime with the specified number of hours added. 38 LocalTime plusMinutes(long minutesToAdd) Returns a copy of this LocalTime with the specified number of minutes added. 39 LocalTime plusNanos(long nanos) Returns a copy of this LocalTime with the specified number of nanoseconds added. 40 LocalTime plusSeconds(long seconds) Returns a copy of this LocalTime with the specified number of seconds added. 41 <R> R query(TemporalQuery<R> query) Queries this time using the specified query. 42 ValueRange range(TemporalField field) Gets the range of valid values for the specified field. 43 long toNanoOfDay() Extracts the time as nanos of day, from 0 to 24 * 60 * 60 * 1,000,000,000 – 1. 44 int toSecondOfDay() Extracts the time as seconds of day, from 0 to 24 * 60 * 60 – 1. 45 String toString() Outputs this date as a String, such as 10:15. 46 LocalTime truncatedTo(TemporalUnit unit) Returns a copy of this LocalTime with the time truncated. 47 long until(Temporal endExclusive, TemporalUnit unit) Calculates the amount of time until another time in terms of the specified unit. 48 LocalTime with(TemporalAdjuster adjuster) Returns an adjusted copy of this time. 49 LocalTime with(TemporalField field, long newValue) Returns a copy of this time with the specified field set to a new value. 50 LocalTime withHour(int hour) Returns a copy of this LocalTime with the hour-of-day altered. 51 LocalTime withMinute(int minute) Returns a copy of this LocalTime with the minute-of-hour altered. 52 LocalTime withNano(int nanoOfSecond) Returns a copy of this LocalTime with the nano-of-second altered. 53 LocalTime withSecond(int second) Returns a copy of this LocalTime with the second-of-minute altered. Methods inherited This class inherits methods from the following classes − Java.lang.Object Print Page Previous Next Advertisements ”;
java.time – Discussion
Discuss java.time package ”; Previous Next Java 8 has introduced new Date and Time API under java.time package. This reference will take you through simple and practical methods available in java.time package. Print Page Previous Next Advertisements ”;
java.time – OffsetTime
java.time.OffsetTime Class ”; Previous Next Introduction The java.time.OffsetTime class represents a time with an offset from UTC/Greenwich in the ISO-8601 calendar system, such as 10:15:30+01:00. Class declaration Following is the declaration for java.time.OffsetTime class − public final class OffsetTime extends Object implements Temporal, TemporalAdjuster, Comparable<OffsetTime>, Serializable Field Following are the fields for java.time.OffsetTime class − static OffsetTime MAX − The maximum supported OffsetTime, ”23:59:59.999999999-18:00”. static OffsetTime MIN − The minimum supported OffsetTime, ”00:00:00+18:00”. Class methods Sr.No. Method & Description 1 Temporal adjustInto(Temporal temporal) Adjusts the specified temporal object to have the same date and time as this object. 2 OffsetDateTime atDate(LocalDate date) Combines this time with a date to create a OffsetDateTime. 3 int compareTo(OffsetTime other) Compares this time to another time. 4 boolean equals(Object obj) Checks if this time is equal to another time. 5 String format(DateTimeFormatter formatter) Formats this time using the specified formatter. 6 static OffsetTime from(TemporalAccessor temporal) Obtains an instance of OffsetTime from a temporal object. 7 int get(TemporalField field) Gets the value of the specified field from this time as an int. 8 int getHour() Gets the hour-of-day field. 9 long getLong(TemporalField field) Gets the value of the specified field from this time as a long. 10 int getMinute() Gets the minute-of-hour field. 11 int getNano() Gets the nano-of-second field. 12 ZoneOffset getOffset() Gets the zone offset, such as ”+01:00”. 13 int getSecond() Gets the second-of-minute field. 14 int hashCode() A hash code for this time. 15 boolean isAfter(OffsetTime other) Checks if the instant of this OffsetTime is after that of the specified time applying both times to a common date. 16 boolean isBefore(OffsetTime other) Checks if the instant of this OffsetTime is before that of the specified time applying both times to a common date. 17 boolean isEqual(OffsetTime other) Checks if the instant of this OffsetTime is equal to that of the specified time applying both times to a common date. 18 boolean isSupported(TemporalField field) Checks if the specified field is supported. 19 boolean isSupported(TemporalUnit unit) Checks if the specified unit is supported. 20 OffsetTime minus(long amountToSubtract, TemporalUnit unit) Returns a copy of this time with the specified amount subtracted. 21 OffsetTime minus(TemporalAmount amountToSubtract) Returns a copy of this time with the specified amount subtracted. 22 OffsetTime minusHours(long hoursToSubtract) Returns a copy of this OffsetTime with the specified number of hours subtracted. 23 OffsetTime minusMinutes(long minutesToSubtract) Returns a copy of this OffsetTime with the specified number of minutes subtracted. 24 OffsetTime minusNanos(long nanos) Returns a copy of this OffsetTime with the specified number of nanoseconds subtracted. 25 OffsetTime minusSeconds(long seconds) Returns a copy of this OffsetTime with the specified number of seconds subtracted. 26 static OffsetTime now() Obtains the current time from the system clock in the default time-zone. 27 static OffsetTime now(Clock clock) Obtains the current time from the specified clock. 28 static OffsetTime now(ZoneId zone) Obtains the current time from the system clock in the specified time-zone. 29 static OffsetTime of(int hour, int minute, int second, int nanoOfSecond, ZoneOffset offset) Obtains an instance of OffsetTime from an hour, minute, second, nanosecond and an offset. 30 static OffsetTime of(LocalTime time, ZoneOffset offset) Obtains an instance of OffsetTime from a local time and an offset. 31 static OffsetTime ofInstant(Instant instant, ZoneId zone) Obtains an instance of OffsetTime from an Instant and zone ID. 32 static OffsetTime parse(CharSequence text) Obtains an instance of OffsetTime from a text string such as 10:15:30+01:00. 33 static OffsetTime parse(CharSequence text, DateTimeFormatter formatter) Obtains an instance of OffsetTime from a text string using a specific formatter. 34 OffsetTime plus(long amountToAdd, TemporalUnit unit) Returns a copy of this time with the specified amount added. 35 OffsetTime plus(TemporalAmount amountToAdd) Returns a copy of this time with the specified amount added. 36 OffsetTime plusHours(long hoursToAdd) Returns a copy of this OffsetTime with the specified number of hours added. 37 OffsetTime plusMinutes(long minutesToAdd) Returns a copy of this OffsetTime with the specified number of minutes added. 38 OffsetTime plusNanos(long nanos) Returns a copy of this OffsetTime with the specified number of nanoseconds added. 39 OffsetTime plusSeconds(long seconds) Returns a copy of this OffsetTime with the specified number of seconds added. 40 <R> R query(TemporalQuery<R> query) Queries this time using the specified query. 41 ValueRange range(TemporalField field) Gets the range of valid values for the specified field. 42 LocalTime toLocalTime() Gets the LocalTime part of this date-time. 43 String toString() Outputs this date as a String, such as 10:15. 44 OffsetTime truncatedTo(TemporalUnit unit) Returns a copy of this OffsetTime with the time truncated. 45 long until(Temporal endExclusive, TemporalUnit unit) Calculates the amount of time until another time in terms of the specified unit. 46 OffsetTime with(TemporalAdjuster adjuster) Returns an adjusted copy of this time. 47 OffsetTime with(TemporalField field, long newValue) Returns a copy of this time with the specified field set to a new value. 48 OffsetTime withHour(int hour) Returns a copy of this OffsetTime with the hour-of-day altered. 49 OffsetTime withMinute(int minute) Returns a copy of this OffsetTime with the minute-of-hour altered. 50 OffsetTime withNano(int nanoOfSecond) Returns a copy of this OffsetTime with the nano-of-second altered. 51 OffsetTime withOffsetSameInstant(ZoneOffset offset) Returns a copy of this OffsetTime with the specified offset ensuring that the result is at the same instant on an implied day. 52 OffsetTime withOffsetSameLocal(ZoneOffset offset) Returns a copy of this OffsetTime with the specified offset ensuring that the result has the same local time. 53 OffsetTime withSecond(int second) Returns a copy of this OffsetTime with the second-of-minute altered. Methods inherited This class inherits methods from the following classes − Java.lang.Object Print Page Previous Next Advertisements ”;
java.time – ZoneOffset
java.time.ZoneOffset Class ”; Previous Next Introduction The java.time.ZoneOffset class represents a time-zone offset from Greenwich/UTC, such as +02:00. Class declaration Following is the declaration for java.time.ZoneOffset class − public final class ZoneOffset extends ZoneId implements TemporalAccessor, TemporalAdjuster, Comparable<ZoneOffset>, Serializable Field Following are the fields for Java.time.ZoneOffset class − static ZoneOffset MAX − Constant for the maximum supported offset. static ZoneOffset MIN − Constant for the minimum supported offset. static ZoneOffset UTC − The time-zone offset for UTC, with an ID of ”Z”. Class methods Sr.No. Method & Description 1 Temporal adjustInto(Temporal temporal) Adjusts the specified temporal object to have the same offset as this object. 2 int compareTo(ZoneOffset other) Compares this offset to another offset in descending order. 3 boolean equals(Object obj) Checks if this offset is equal to another offset. 4 static ZoneOffset from(TemporalAccessor temporal) Obtains an instance of ZoneOffset from a temporal object. 5 int get(TemporalField field) Gets the value of the specified field from this offset as an int. 6 String getId() Gets the normalized zone offset ID. 7 long getLong(TemporalField field) Gets the value of the specified field from this offset as a long. 8 ZoneRules getRules() Gets the associated time-zone rules. 9 int getTotalSeconds() Gets the total zone offset in seconds. 10 int hashCode() A hash code for this offset. 11 boolean isSupported(TemporalField field) Checks if the specified field is supported. 12 static ZoneOffset of(String offsetId) Obtains an instance of ZoneOffset using the ID. 13 static ZoneOffset ofHours(int hours) Obtains an instance of ZoneOffset using an offset in hours. 14 static ZoneOffset ofHoursMinutes(int hours, int minutes) Obtains an instance of ZoneOffset using an offset in hours and minutes. 15 static ZoneOffset ofHoursMinutesSeconds(int hours, int minutes, int seconds) Obtains an instance of ZoneOffset using an offset in hours, minutes and seconds. 16 static ZoneOffset ofTotalSeconds(int totalSeconds) Obtains an instance of ZoneOffset specifying the total offset in seconds. 17 <R> R query(TemporalQuery<R> query) Queries this offset using the specified query. 18 ValueRange range(TemporalField field) Gets the range of valid values for the specified field. 19 String toString() Outputs this offset as a String, using the normalized ID. Methods inherited This class inherits methods from the following classes − Java.time.ZoneId Java.lang.Object Print Page Previous Next Advertisements ”;
java.time – Instant
java.time.Instant Class ”; Previous Next Introduction The java.time.Instant class models a single instantaneous point on the time-line. Class declaration Following is the declaration for java.time.Instant class − public final class Instant extends Object implements Temporal, TemporalAdjuster, Comparable, Serializable Field Following are the fields for Java.time.Instant class − static Instant EPOCH − Constant for the 1970-01-01T00:00:00Z epoch instant. static Instant MAX − The maximum supported Instant, ”1000000000-12-31T23:59:59.999999999Z”. static Instant MIN − The minimum supported Instant, ”-1000000000-01-01T00:00Z”. Class methods Sr.No. Method & Description 1 Temporal adjustInto(Temporal temporal) Adjusts the specified temporal object to have this instant. 2 OffsetDateTime atOffset(ZoneOffset offset) Combines this instant with an offset to create an OffsetDateTime. 3 ZonedDateTime atZone(ZoneId zone) Combines this instant with a time-zone to create a ZonedDateTime. 4 int compareTo(Instant otherInstant) Compares this instant to the specified instant. 5 boolean equals(Object otherInstant) Checks if this instant is equal to the specified instant. 6 static Instant from(TemporalAccessor temporal) Obtains an instance of Instant from a temporal object. 7 int get(TemporalField field) Gets the value of the specified field from this instant as an int. 8 long getEpochSecond() Gets the number of seconds from the Java epoch of 1970-01-01T00:00:00Z. 9 long getLong(TemporalField field) Gets the value of the specified field from this instant as a long. 10 int getNano() Gets the number of nanoseconds, later along the time-line, from the start of the second. 11 int hashCode() Returns a hash code for this instant. 12 boolean isAfter(Instant otherInstant) Checks if this instant is after the specified instant. 13 boolean isBefore(Instant otherInstant) Checks if this instant is before the specified instant. 14 boolean isSupported(TemporalField field) Checks if the specified field is supported. 15 boolean isSupported(TemporalUnit unit) Checks if the specified unit is supported. 16 Instant minus(long amountToSubtract, TemporalUnit unit) Returns a copy of this instant with the specified amount subtracted. 17 Instant minus(TemporalAmount amountToSubtract) Returns a copy of this instant with the specified amount subtracted. 18 Instant minusMillis(long millisToSubtract) Returns a copy of this instant with the specified duration in milliseconds subtracted. 19 Instant minusNanos(long nanosToSubtract) Returns a copy of this instant with the specified duration in nanoseconds subtracted. 20 Instant minusSeconds(long secondsToSubtract) Returns a copy of this instant with the specified duration in seconds subtracted. 21 static Instant now() Obtains the current instant from the system clock. 22 static Instant now(Clock clock) Obtains the current instant from the specified clock. 23 static Instant ofEpochMilli(long epochMilli) Obtains an instance of Instant using milliseconds from the epoch of 1970-01-01T00:00:00Z. 24 static Instant ofEpochSecond(long epochSecond) Obtains an instance of Instant using seconds from the epoch of 1970-01-01T00:00:00Z. 25 static Instant ofEpochSecond(long epochSecond, long nanoAdjustment) Obtains an instance of Instant using seconds from the epoch of 1970-01-01T00:00:00Z and nanosecond fraction of second. 26 static Instant parse(CharSequence text) Obtains an instance of Instant from a text string such as 2007-12-03T10:15:30.00Z. 27 Instant plus(long amountToAdd, TemporalUnit unit) Returns a copy of this instant with the specified amount added. 28 Instant plus(TemporalAmount amountToAdd) Returns a copy of this instant with the specified amount added. 29 Instant plusMillis(long millisToAdd) Returns a copy of this instant with the specified duration in milliseconds added. 30 Instant plusNanos(long nanosToAdd) Returns a copy of this instant with the specified duration in nanoseconds added. 31 Instant plusSeconds(long secondsToAdd) Returns a copy of this instant with the specified duration in seconds added. 32 R query(TemporalQuery query) Queries this instant using the specified query. 33 ValueRange range(TemporalField field) Gets the range of valid values for the specified field. 34 long toEpochMilli() Converts this instant to the number of milliseconds from the epoch of 1970-01-01T00:00:00Z. 35 String toString() A string representation of this instant using ISO-8601 representation. 36 Instant truncatedTo(TemporalUnit unit) Returns a copy of this Instant truncated to the specified unit. 37 long until(Temporal endExclusive, TemporalUnit unit) Calculates the amount of time until another instant in terms of the specified unit. 38 Instant with(TemporalAdjuster adjuster) Returns an adjusted copy of this instant. 39 Instant with(TemporalField field, long newValue) Returns a copy of this instant with the specified field set to a new value. Methods inherited This class inherits methods from the following classes − Java.lang.Object Print Page Previous Next Advertisements ”;
java.time – Period
java.time.Period Class ”; Previous Next Introduction The java.time.Period class models a quantity or amount of time in terms of years, months and days. Class declaration Following is the declaration for java.time.Period class − public final class Period extends Object implements ChronoPeriod, Serializable Field Following are the fields for Java.time.Period class − static Period ZERO − Constant for a Period of zero. Class methods Sr.No. Method & Description 1 Temporal addTo(Temporal temporal) Adds this Period to the specified temporal object. 2 static Period between(LocalDate startInclusive, LocalDate endExclusive) Obtains a Period consisting of the number of years, months, and days between two dates. 3 boolean equals(Object otherPeriod) Checks if this Period is equal to the specified Period. 4 static Duratio from(TemporalAmount amount) Obtains an instance of Period from a temporal amount. 5 long get(TemporalUnit unit) Gets the value of the requested unit. 6 IsoChronology getChronology() Gets the chronology of this period, which is the ISO calendar system. 7 int getDays() Gets the amount of days of this period. 8 int getMonths() Gets the amount of months of this period. 9 List<TemporalUnit> getUnits() Gets the set of units supported by this Period. 10 int hashCode() A hash code for this Period. 11 boolean isNegative() Checks if this Period is negative, excluding zero. 12 boolean isZero() Checks if this Period is zero length. 13 Period minus(TemporalAmount amountToSubtract) Returns a copy of this Period with the specified Period subtracted. 14 Period minusDays(long daysToSubtract) Returns a copy of this period with the specified days subtracted. 15 Period minusMonths(long months) Returns a copy of this period with the specified months subtracted. 16 Period minusYears(long years) Returns a copy of this period with the specified years subtracted. 17 Period multipliedBy(long multiplicand) Returns a copy of this Period multiplied by the scalar. 18 Period negated() Returns a copy of this Period with the length negated. 19 Period normalized() Returns a copy of this period with the years and months normalized. 20 static Period of(int years, int months, int days) Obtains a Period representing a number of years, months and days. 21 static Period ofDays(int days) Obtains a Period representing a number of days. 22 static Period ofMonths(int months) Obtains a Period representing a number of months. 23 static Period ofWeeks(int weeks) Obtains a Period representing a number of weeks. 24 static Period ofYears(int years) Obtains a Period representing a number of weeks. 25 static Period parse(CharSequence text) Obtains a Period from a text string such as PnYnMnD. 26 Period plus(TemporalAmount amountToAdd) Returns a copy of this Period with the specified Period added. 27 Period plusDays(long daysToAdd) Returns a copy of this period with the specified days added. 28 Period plusMonths(long monthsToAdd) Returns a copy of this period with the specified months added. 29 Period plusYears(long yearsToAdd) Returns a copy of this period with the specified years added. 30 Temporal subtractFrom(Temporal temporal) Subtracts this Period from the specified temporal object. 31 String toString() A string representation of this Period using ISO-8601 seconds based representation, such as PT8H6M12.345S. 32 long toTotalMonths() Gets the total number of months in this period. 33 Period withDays(int days) Returns a copy of this period with the specified amount of days. 34 Period withMonths(int months) Returns a copy of this period with the specified amount of months. 35 Period withYears(int years) Returns a copy of this period with the specified amount of Years. Methods inherited This class inherits methods from the following classes − Java.lang.Object Print Page Previous Next Advertisements ”;
java.time – Duration
java.time.Duration Class ”; Previous Next Introduction The java.time.Duration class models a quantity or amount of time in terms of seconds and nanoseconds. It can be accessed using other duration-based units, such as minutes and hours. Class declaration Following is the declaration for java.time.Duration class − public final class Duration extends Object implements TemporalAmount, Comparable<Duration>, Serializable Field Following are the fields for java.time.Duration class − static Duration ZERO − Constant for a duration of zero. Class methods Sr.No. Method & Description 1 Duration abs() Returns a copy of this duration with a positive length. 2 Temporal addTo(Temporal temporal) Adds this duration to the specified temporal object. 3 static Duration between(Temporal startInclusive, Temporal endExclusive) Obtains a Duration representing the duration between two temporal objects. 4 int compareTo(Duration otherDuration) Compares this duration to the specified Duration. 5 Duration dividedBy(long divisor) Returns a copy of this duration divided by the specified value. 6 boolean equals(Object otherDuration) Checks if this duration is equal to the specified Duration. 7 static Duratio from(TemporalAmount amount) Obtains an instance of Duration from a temporal amount. 8 long get(TemporalUnit unit) Gets the value of the requested unit. 9 int getNano() Gets the number of nanoseconds within the second in this duration. 10 long getSeconds() Gets the number of seconds in this duration. 11 List<TemporalUnit> getUnits() Gets the set of units supported by this duration. 12 int hashCode() A hash code for this duration. 13 boolean isNegative() Checks if this duration is negative, excluding zero. 14 boolean isZero() Checks if this duration is zero length. 15 Duration minus(Duration duration) Returns a copy of this duration with the specified duration subtracted. 16 Duration minus(long amountToSubtract, TemporalUnit unit) Returns a copy of this duration with the specified duration subtracted. 17 Duration minusDays(long daysToSubtract) Returns a copy of this duration with the specified duration in standard 24 hour days subtracted. 18 Duration minusHours(long hoursToSubtract) Returns a copy of this duration with the specified duration in hours subtracted. 19 Duration minusMillis(long millisToSubtract) Returns a copy of this duration with the specified duration in milliseconds subtracted. 20 Duration minusMinutes(long minutesToSubtract) Returns a copy of this duration with the specified duration in minutes subtracted. 21 Duration minusNanos(long nanosToSubtract) Returns a copy of this duration with the specified duration in nanoseconds subtracted. 22 Duration minusSeconds(long secondsToSubtract) Returns a copy of this duration with the specified duration in seconds subtracted. 23 Duration multipliedBy(long multiplicand) Returns a copy of this duration multiplied by the scalar. 24 Duration negated() Returns a copy of this duration with the length negated. 25 static Duration of(long amount, TemporalUnit unit) Obtains a Duration representing an amount in the specified unit. 26 static Duration ofDays(long days) Obtains a Duration representing a number of standard 24 hour days. 27 static Duration ofHours(long hours) Obtains a Duration representing a number of standard hours. 28 static Duration ofMillis(long millis) Obtains a Duration representing a number of milliseconds. 29 static Duration ofMinutes(long minutes) Obtains a Duration representing a number of standard minutes. 30 static Duration ofNanos(long nanos) Obtains a Duration representing a number of nanoseconds. 31 static Duration ofSeconds(long seconds) Obtains a Duration representing a number of seconds. 32 static Duration ofSeconds(long seconds, long nanoAdjustment) Obtains a Duration representing a number of seconds and an adjustment in nanoseconds. 33 static Duration parse(CharSequence text) Obtains a Duration from a text string such as PnDTnHnMn.nS. 34 Duration plus(Duration duration) Returns a copy of this duration with the specified duration added. 35 Duration plus(long amountToAdd, TemporalUnit unit) Returns a copy of this duration with the specified duration added. 36 Duration plusDays(long daysToAdd) Returns a copy of this duration with the specified duration in standard 24 hour days added. 37 Duration plusHours(long hoursToAdd) Returns a copy of this duration with the specified duration in hours added. 38 Duration plusMillis(long millisToAdd) Returns a copy of this duration with the specified duration in milliseconds added. 39 Duration plusMinutes(long minutesToAdd) Returns a copy of this duration with the specified duration in minutes added. 40 Duration plusNanos(long nanosToAdd) Returns a copy of this duration with the specified duration in nanoseconds added. 41 Duration plusSeconds(long secondsToAdd) Returns a copy of this duration with the specified duration in seconds added. 42 Temporal subtractFrom(Temporal temporal) Subtracts this duration from the specified temporal object. 43 long toDays() Gets the number of days in this duration. 44 long toHours() Gets the number of hours in this duration. 45 long toMillis() Converts this duration to the total length in milliseconds. 46 long toMinutes() Gets the number of minutes in this duration. 47 long toNanos() Converts this duration to the total length in nanoseconds expressed as a long. 48 String toString() A string representation of this duration using ISO-8601 seconds based representation, such as PT8H6M12.345S. 49 Duration withNanos(int nanoOfSecond) Returns a copy of this duration with the specified nano-of-second. 50 Duration withSeconds(long seconds) Returns a copy of this duration with the specified amount of seconds. Methods inherited This class inherits methods from the following classes − Java.lang.Object Print Page Previous Next Advertisements ”;
java.time – Clock
java.time.Clock Class ”; Previous Next Introduction The java.time.Clock class provides access to the current instant, date and time using a time-zone. Class declaration Following is the declaration for java.io.Clock class − public abstract class Clock extends Object Class constructors Sr.No. Constructor & Description 1 protected Clock() This creates a Clock. Class methods Sr.No. Method & Description 1 boolean equals(Object obj) This method checks if this clock is equal to another clock. 2 static Clock fixed(Instant fixedInstant, ZoneId zone) This method obtains a clock that always returns the same instant. 3 abstract ZoneId getZone() This method gets the time-zone being used to create dates and times. 4 int hashCode() This method gets a hash code for this clock. 5 int instant() This method gets the current instant of the clock. 6 long millis() This method gets the current millisecond instant of the clock. 7 static Clock offset(Clock baseClock, Duration offsetDuration) This method obtains a clock that returns instants from the specified clock with the specified duration added. 8 static Clock system(ZoneId zone) This method obtains a clock that returns the current instant using best available system clock. 9 static Clock systemDefaultZone() This method obtains a clock that returns the current instant using the best available system clock, converting to date and time using the default time-zone. 10 static Clock systemUTC() This method obtains a clock that returns the current instant using the best available system clock, converting to date and time using the UTC time-zone. 11 static Clock tick(Clock baseClock, Duration tickDuration) This method obtains a clock that returns instants from the specified clock truncated to the nearest occurrence of the specified duration. 12 static Clock tickMinutes(ZoneId zone) This method obtains a clock that returns the current instant ticking in whole minutes using best available system clock. 13 static Clock tickSeconds(ZoneId zone) This method obtains a clock that returns the current instant ticking in whole seconds using best available system clock. 14 static Clock withZone(ZoneId zone) This method returns a copy of this clock with a different time-zone. Methods inherited This class inherits methods from the following classes − Java.lang.Object Print Page Previous Next Advertisements ”;
java.time – LocalDate
java.time.LocalDate Class ”; Previous Next Introduction The java.time.LocalDate class represents a date without a time-zone in the ISO-8601 calendar system, such as 2007-12-03. Class declaration Following is the declaration for java.time.LocalDate class − public final class LocalDate extends Object implements Temporal, TemporalAdjuster, ChronoLocalDate, Serializable Field Following are the fields for java.time.LocalDate class − static LocalDate MAX − The maximum supported LocalDate, ”+999999999-12-31”. static LocalDate MIN − The minimum supported LocalDate, ”-999999999-01-01”. Class methods Sr.No. Method & Description 1 Temporal adjustInto(Temporal temporal) Adjusts the specified temporal object to have the same date as this object. 2 LocalDateTime atStartOfDay() Combines this date with the time of midnight to create a LocalDateTime at the start of this date. 3 ZonedDateTime atStartOfDay(ZoneId zone) Returns a zoned date-time from this date at the earliest valid time according to the rules in the time-zone. 4 LocalDateTime atTime(int hour, int minute) Combines this date with a time to create a LocalDateTime. 5 LocalDateTime atTime(int hour, int minute, int second) Combines this date with a time to create a LocalDateTime. 6 LocalDateTime atTime(int hour, int minute, int second, int nanoOfSecond) Combines this date with a time to create a LocalDateTime. 7 LocalDateTime atTime(LocalTime time) Combines this date with a time to create a LocalDateTime. 8 OffsetDateTime atTime(OffsetTime time) Combines this date with an offset time to create an OffsetDateTime. 9 int compareTo(ChronoLocalDate other) Compares this date to another date. 10 boolean equals(Object obj) Checks if this date is equal to another date. 11 String format(DateTimeFormatter formatter) Formats this date using the specified formatter. 12 static LocalDate from(TemporalAccessor temporal) Obtains an instance of LocalDate from a temporal object. 13 int get(TemporalField field) Gets the value of the specified field from this date as an int. 14 IsoChronology getChronology() Gets the chronology of this date, which is the ISO calendar system. 15 int getDayOfMonth() Gets the day-of-month field. 16 DayOfWeek getDayOfWeek() Gets the day-of-week field, which is an enum DayOfWeek. 17 int getDayOfYear() Gets the day-of-year field. 18 Era getEra() Gets the era applicable at this date. 19 long getLong(TemporalField field) Gets the value of the specified field from this date as a long. 20 Month getMonth() Gets the month-of-year field using the Month enum. 21 int getMonthValue() Gets the month-of-year field from 1 to 12. 22 int getYear() Gets the year field. 23 int hashCode() A hash code for this date. 24 boolean isAfter(ChronoLocalDate other) Checks if this date is after the specified date. 25 boolean isBefore(ChronoLocalDate other) Checks if this date is before the specified date. 26 boolean isEqual(ChronoLocalDate other) Checks if this date is equal to the specified date. 27 boolean isLeapYear() Checks if the year is a leap year, according to the ISO proleptic calendar system rules. 28 boolean isSupported(TemporalField field) Checks if the specified field is supported. 29 boolean isSupported(TemporalUnit unit) Checks if the specified unit is supported. 30 int lengthOfMonth() Returns the length of the month represented by this date. 31 int lengthOfYear() Returns the length of the year represented by this date. 32 LocalDate minus(long amountToSubtract, TemporalUnit unit) Returns a copy of this date with the specified amount subtracted. 33 LocalDate minus(TemporalAmount amountToSubtract) Returns a copy of this date with the specified amount subtracted. 34 LocalDate minusDays(long daysToSubtract) Returns a copy of this LocalDate with the specified number of days subtracted. 35 LocalDate minusMonths(long monthsToSubtract) Returns a copy of this LocalDate with the specified number of months subtracted. 36 LocalDate minusWeeks(long weeksToSubtract) Returns a copy of this LocalDate with the specified number of weeks subtracted. 37 LocalDate minusYears(long yearsToSubtract) Returns a copy of this LocalDate with the specified number of years subtracted. 38 static LocalDate now() Obtains the current date from the system clock in the default time-zone. 39 static LocalDate now(Clock clock) Obtains the current date from the specified clock. 40 static LocalDate now(ZoneId zone) Obtains the current date from the system clock in the specified time-zone. 41 static LocalDate of(int year, int month, int dayOfMonth) Obtains an instance of LocalDate from a year, month and day. 42 static LocalDate of(int year, Month month, int dayOfMonth) Obtains an instance of LocalDate from a year, month and day. 43 static LocalDate ofEpochDay(long epochDay) Obtains an instance of LocalDate from the epoch day count. 44 static LocalDate ofYearDay(int year, int dayOfYear) Obtains an instance of LocalDate from a year and day-of-year. 45 static LocalDate parse(CharSequence text) Obtains an instance of LocalDate from a text string such as 2007-12-03. 46 static LocalDate parse(CharSequence text, DateTimeFormatter formatter) Obtains an instance of LocalDate from a text string using a specific formatter. 47 LocalDate plus(long amountToAdd, TemporalUnit unit) Returns a copy of this date with the specified amount added. 48 LocalDate plus(TemporalAmount amountToAdd) Returns a copy of this date with the specified amount added. 49 LocalDate plusDays(long daysToAdd) Returns a copy of this LocalDate with the specified number of days added. 50 LocalDate plusMonths(long monthsToAdd) Returns a copy of this LocalDate with the specified number of months added. 51 LocalDate plusWeeks(long weeksToAdd) Returns a copy of this LocalDate with the specified number of weeks added. 52 LocalDate plusYears(long yearsToAdd) Returns a copy of this LocalDate with the specified number of years added. 53 <R> R query(TemporalQuery<R> query) Queries this date using the specified query. 54 ValueRange range(TemporalField field) Gets the range of valid values for the specified field. 55 long toEpochDay() Converts this date to the Epoch Day. 56 String toString() Outputs this date as a String, such as 2007-12-03. 57 Period until(ChronoLocalDate endDateExclusive) Calculates the period between this date and another date as a Period. 58 long until(Temporal endExclusive, TemporalUnit unit) Calculates the amount of time until another date in terms of the specified unit. 59 LocalDate with(TemporalAdjuster adjuster) Returns an adjusted copy of this date. 60 LocalDate with(TemporalField field, long newValue) Returns a copy of this date with the specified field set to a new value. 61 LocalDate withDayOfMonth(int dayOfMonth) Returns a copy of this LocalDate with the day-of-month altered. 62 LocalDate withDayOfYear(int dayOfYear) Returns a copy of this LocalDate with the