public final class OffsetDayTime extends java.lang.Object implements java.lang.Comparable<OffsetDayTime>, java.io.Serializable
Note that, internally, this class, like all the other date-related classes in this package, uses the modern Gregorian calendar for all validation and calculations. The Gregorian calendar was introduced in 1582 but this class applies it to earlier dates as well (so using what is known as the "proleptic Gregorian calendar"). This fits with the ISO 8601 standard and is how the java.time
package works by default, but it's not how java.util.Calendar
works by default, so bear this in mind if you are working with dates from 1582 or before. You are of course unlikely to find good weather data from that far back, but we mention this just in case you find yourself using this class for other purposes as well!
Instances of this class are immutable. You can safely reuse them and call them from multiple threads at once.
Constructor and Description |
---|
OffsetDayTime(DayTime dayTime,
int offsetTotalMinutes)
Constructs an
OffsetDayTime object with the specified local
date-time and UTC offset. |
OffsetDayTime(Day day,
Time time,
int offsetTotalMinutes)
Constructs an
OffsetDayTime object with the specified local
date, time, and UTC offset. |
Modifier and Type | Method and Description |
---|---|
boolean |
after(OffsetDayTime comparisonOffsetDayTime)
Returns
true if the instant in time represented by this
OffsetDayTime is after the instant in time represented by
comparisonOffsetDayTime ; false otherwise. |
boolean |
before(OffsetDayTime comparisonOffsetDayTime)
Returns
true if the instant in time represented by this
OffsetDayTime is before the instant in time represented by
comparisonOffsetDayTime ; false otherwise. |
int |
compareTo(OffsetDayTime comparisonOffsetDayTime)
Compares two
OffsetDayTime objects for chronological
ordering, considering first the instants in time that they represent, and
only considering their local clock times if those instants are identical. |
Day |
day()
Returns a non-null
Day object representing the YYYY-MM-DD
component of this OffsetDayTime . |
int |
dayOfMonth()
Returns a number between 1 and 31 (inclusive) indicating the
day-of-the-month component of this
OffsetDayTime . |
DayOfWeek |
dayOfWeek()
Returns a non-null
DayOfWeek object indicating the
day of the week of this OffsetDayTime . |
int |
dayOfYear()
Returns a number between 1 and 366 inclusive (365 for non-leap years)
indicating the day of the year of this
OffsetDayTime . |
DayTime |
dayTime()
Returns a non-null
DayTime object representing the
YYYY-MM-DDThh:mm component of this OffsetDayTime . |
boolean |
equals(java.lang.Object o)
Returns
true if o is an
OffsetDayTime representing the same date-time and UTC offset
as this OffsetDayTime ; false otherwise. |
static OffsetDayTime |
fromString(java.lang.String dateTimeAndOffsetString)
Parses a string date-time with UTC-offset time-zone information included
in ISO format like e.g.
2020-04-10T12:35Z (
Z indicating the UTC time-zone i.e. no offset), or
2019-01-31T18:22-08:00 (8 hours behind UTC). |
int |
hashCode()
Overridden to ensure consistency with
equals . |
int |
hour()
Returns a number between 0 and 23 (inclusive) representing the hour
component of this
OffsetDayTime . |
int |
minute()
Returns a number between 0 and 59 (inclusive) representing the minute
component of this
OffsetDayTime . |
long |
minutesAfter(OffsetDayTime comparisonOffsetDayTime)
Returns the number of minutes that the instant in time represented by
this
OffsetDayTime is after that represented by
comparisonOffsetDayTime , which will be negative if this
OffsetDayTime comes first chronologically. |
long |
minutesBefore(OffsetDayTime comparisonOffsetDayTime)
Returns the number of minutes that the instant in time represented by
this
OffsetDayTime is before that represented by
comparisonOffsetDayTime , which will be negative if
comparisonOffsetDayTime comes first chronologically. |
int |
monthOfYear()
Returns a number between 1 (January) and 12 (December) representing the
month-of-the-year component of this
OffsetDayTime . |
static OffsetDayTime |
of(DayTime dayTime,
int offsetTotalMinutes)
Returns a non-null
OffsetDayTime object with the specified
local date-time and UTC offset. |
static OffsetDayTime |
of(Day day,
Time time,
int offsetTotalMinutes)
Returns a non-null
OffsetDayTime object with the specified
local date, time, and UTC offset. |
int |
offsetTotalMinutes()
Returns the total number of minutes by which this
OffsetDayTime is offset from UTC; for example for
2020-08-15T11:43+01:00 this would return 60, and for
2020-08-15T11:43-05:00 it would return -300. |
Time |
time()
Returns a non-null
Time object representing the hh:mm
component of this OffsetDayTime . |
java.util.Date |
toDate()
Returns the instant in time represented by this
OffsetDayTime as a non-null java.util.Date . |
long |
toEpochMilli()
Returns the instant in time represented by this
OffsetDayTime as the number of milliseconds since the epoch
of 1970-01-01T00:00Z . |
java.lang.String |
toString()
Returns a non-null, non-empty string representation of this
OffsetDayTime in ISO format like
2020-08-15T17:57+01:00 , 2020-08-15T12:57-05:00 ,
or 2020-08-15T16:57Z . |
int |
year()
Returns a number indicating the year component of this
OffsetDayTime . |
public OffsetDayTime(DayTime dayTime, int offsetTotalMinutes)
OffsetDayTime
object with the specified local
date-time and UTC offset.dayTime
- the local YYYY-MM-DDThh:mm date-time.offsetTotalMinutes
- the total minutes offset from UTC (e.g. 60 for
the +01:00 time-zone, -300 for the -05:00 time-zone, 0 for the
UTC/GMT time-zone).java.lang.NullPointerException
- if dayTime
is null
.java.lang.IllegalArgumentException
- if offsetTotalMinutes
is
less than -1080 (for a -18:00 time-zone) or greater than 1080
(for a +18:00 time-zone).public OffsetDayTime(Day day, Time time, int offsetTotalMinutes)
OffsetDayTime
object with the specified local
date, time, and UTC offset.day
- the local YYYY-MM-DD date.time
- the local hh:mm time.offsetTotalMinutes
- the total minutes offset from UTC (e.g. 60 for
the +01:00 time-zone, -300 for the -05:00 time-zone, 0 for the
UTC/GMT time-zone).java.lang.NullPointerException
- if day
or time
is
null
.java.lang.IllegalArgumentException
- if offsetTotalMinutes
is
less than -1080 (for a -18:00 time-zone) or greater than 1080
(for a +18:00 time-zone).public static OffsetDayTime of(DayTime dayTime, int offsetTotalMinutes)
OffsetDayTime
object with the specified
local date-time and UTC offset.dayTime
- the local YYYY-MM-DDThh:mm date-time.offsetTotalMinutes
- the total minutes offset from UTC (e.g. 60 for
the +01:00 time-zone, -300 for the -05:00 time-zone, 0 for the
UTC/GMT time-zone).java.lang.NullPointerException
- if dayTime
is null
.java.lang.IllegalArgumentException
- if offsetTotalMinutes
is
less than -1080 (for a -18:00 time-zone) or greater than 1080
(for a +18:00 time-zone).public static OffsetDayTime of(Day day, Time time, int offsetTotalMinutes)
OffsetDayTime
object with the specified
local date, time, and UTC offset.day
- the local YYYY-MM-DD date.time
- the local hh:mm time.offsetTotalMinutes
- the total minutes offset from UTC (e.g. 60 for
the +01:00 time-zone, -300 for the -05:00 time-zone, 0 for the
UTC/GMT time-zone).java.lang.NullPointerException
- if day
or time
is
null
.java.lang.IllegalArgumentException
- if offsetTotalMinutes
is
less than -1080 (for a -18:00 time-zone) or greater than 1080
(for a +18:00 time-zone).public DayTime dayTime()
DayTime
object representing the
YYYY-MM-DDThh:mm component of this OffsetDayTime
.public int offsetTotalMinutes()
OffsetDayTime
is offset from UTC; for example for
2020-08-15T11:43+01:00 this would return 60, and for
2020-08-15T11:43-05:00 it would return -300.public Day day()
Day
object representing the YYYY-MM-DD
component of this OffsetDayTime
.public Time time()
Time
object representing the hh:mm
component of this OffsetDayTime
.public int year()
OffsetDayTime
.public int monthOfYear()
OffsetDayTime
.public int dayOfMonth()
OffsetDayTime
.public DayOfWeek dayOfWeek()
DayOfWeek
object indicating the
day of the week of this OffsetDayTime
.public int dayOfYear()
OffsetDayTime
.public int hour()
OffsetDayTime
.public int minute()
OffsetDayTime
.public long toEpochMilli()
OffsetDayTime
as the number of milliseconds since the epoch
of 1970-01-01T00:00Z
.
With this method you can create a java.time.Instant
from an
OffsetDayTime
as follows:
Instant.ofEpochMilli(offsetDayTime.toEpochMilli())
public java.util.Date toDate()
OffsetDayTime
as a non-null java.util.Date
.
This is just a shortcut for:
new Date(offsetDayTime.toEpochMilli())
public static OffsetDayTime fromString(java.lang.String dateTimeAndOffsetString)
2020-04-10T12:35Z
(
Z
indicating the UTC time-zone i.e. no offset), or
2019-01-31T18:22-08:00
(8 hours behind UTC).
In the part of the string before the time-zone info, this will also
accept the variations allowed by DayTime.fromString(java.lang.String)
. The colon in
the time-zone info is optional too. But in most cases it makes sense to
stick with ISO format as in the examples above.
OffsetDayTime
object corresponding to the
date-time and UTC offset represented by
dateTimeAndOffsetString
.java.lang.NullPointerException
- if dateTimeAndOffsetString
is
null
.java.lang.NumberFormatException
- if dateTimeAndOffsetString
has
an invalid format, or represents a non-existent date-time or one
that is outside the range allowed by Day
(0001-01-01 to
9999-12-31 inclusive).toString()
public java.lang.String toString()
OffsetDayTime
in ISO format like
2020-08-15T17:57+01:00
, 2020-08-15T12:57-05:00
,
or 2020-08-15T16:57Z
.
In the examples above:
+01:00
in 2020-08-15T17:57+01:00
indicates a time-zone 1 hour ahead of UTC (i.e. a UTC offset of +60
minutes);-05:00
in 2020-08-15T12:57-05:00
indicates a time-zone 5 hours behind UTC (i.e. a UTC offset of -300
minutes); andZ
in 2020-08-15T16:57Z
indicates the
UTC time-zone itself (i.e. no UTC offset, or a UTC offset of zero
minutes).toString
in class java.lang.Object
fromString(java.lang.String)
public boolean equals(java.lang.Object o)
true
if o
is an
OffsetDayTime
representing the same date-time and UTC offset
as this OffsetDayTime
; false
otherwise.equals
in class java.lang.Object
public int hashCode()
equals
.hashCode
in class java.lang.Object
public int compareTo(OffsetDayTime comparisonOffsetDayTime)
OffsetDayTime
objects for chronological
ordering, considering first the instants in time that they represent, and
only considering their local clock times if those instants are identical.
When two OffsetDayTime
objects represent the same instant in
time but in different time-zones (e.g. like how 2020-02-15T12:36-08:00
and 2020-02-15T15:36-05:00 are in different time-zones but actually
represent the same instant in time), this will order the one with the
earlier local dayTime()
first (so 2020-02-15T12:36-08:00 will be
ordered before 2020-02-15T15:36-05:00). In this way this
compareTo
method remains consistent with equals(java.lang.Object)
.
compareTo
in interface java.lang.Comparable<OffsetDayTime>
comparisonOffsetDayTime
- the OffsetDayTime
to be
compared. Cannot be null
.OffsetDayTime
represents
an instant in time before that of
comparisonOffsetDayTime
(or they represent the same
instant in time but this OffsetDayTime
has an
earlier local dayTime()
); zero if this
OffsetDayTime
is equal to
comparisonOffsetDayTime
(which means they both
represent the same instant in time and have the same UTC offset);
or a positive integer if this OffsetDayTime
represents an instant in time after that of
comparisonOffsetDayTime
(or they represent the same
instant in time but this OffsetDayTime
has a later
local dayTime()
).java.lang.NullPointerException
- if comparisonOffsetDayTime
is
null
.before(net.degreedays.time.OffsetDayTime)
,
after(net.degreedays.time.OffsetDayTime)
public boolean before(OffsetDayTime comparisonOffsetDayTime)
true
if the instant in time represented by this
OffsetDayTime
is before the instant in time represented by
comparisonOffsetDayTime
; false
otherwise.
The comparison made by this method is different to that made by
compareTo(net.degreedays.time.OffsetDayTime)
because this method considers only whether the instant
in time that this OffsetDayTime
represents is before that
represented by comparisonOffsetDayTime
. Consider for example
2020-02-15T12:36-08:00 and 2020-02-15T15:36-05:00... Both represent the
same instant in time, but in different time-zones. This method will never
put one before the other, but compareTo(net.degreedays.time.OffsetDayTime)
will order
2020-02-15T12:36-08:00 first (as its docs explain).
comparisonOffsetDayTime
- the OffsetDayTime
to compare
with this OffsetDayTime
. Cannot be null
.java.lang.NullPointerException
- if comparisonOffsetDayTime
is
null
.after(net.degreedays.time.OffsetDayTime)
,
compareTo(net.degreedays.time.OffsetDayTime)
public boolean after(OffsetDayTime comparisonOffsetDayTime)
true
if the instant in time represented by this
OffsetDayTime
is after the instant in time represented by
comparisonOffsetDayTime
; false
otherwise.
The comparison made by this method is different to that made by
compareTo(net.degreedays.time.OffsetDayTime)
because this method considers only whether the instant
in time that this OffsetDayTime
represents is after that
represented by comparisonOffsetDayTime
. Consider for example
2020-02-15T12:36-08:00 and 2020-02-15T15:36-05:00... Both represent the
same instant in time, but in different time-zones. This method will never
put one after the other, but compareTo(net.degreedays.time.OffsetDayTime)
will order
2020-02-15T12:36-08:00 first (as its docs explain).
comparisonOffsetDayTime
- the OffsetDayTime
to compare
with this OffsetDayTime
. Cannot be null
.java.lang.NullPointerException
- if comparisonOffsetDayTime
is
null
.before(net.degreedays.time.OffsetDayTime)
,
compareTo(net.degreedays.time.OffsetDayTime)
public long minutesAfter(OffsetDayTime comparisonOffsetDayTime)
OffsetDayTime
is after that represented by
comparisonOffsetDayTime
, which will be negative if this
OffsetDayTime
comes first chronologically.java.lang.NullPointerException
- if comparisonOffsetDayTime
is
null
.minutesBefore(net.degreedays.time.OffsetDayTime)
public long minutesBefore(OffsetDayTime comparisonOffsetDayTime)
OffsetDayTime
is before that represented by
comparisonOffsetDayTime
, which will be negative if
comparisonOffsetDayTime
comes first chronologically.java.lang.NullPointerException
- if comparisonOffsetDayTime
is
null
.minutesAfter(net.degreedays.time.OffsetDayTime)
See www.degreedays.net/api/ for more about the Degree Days.net API.
You can sign up for a Degree Days.net API account and read the integration guide that is useful and applicable whether you are using Java or not.