|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.joda.time.base.AbstractPartial org.joda.time.base.BasePartial org.joda.time.TimeOfDay
TimeOfDay is an immutable partial supporting the hour, minute, second and millisecond fields.
NOTE: This class only supports the four fields listed above. Thus, you
cannot query the millisOfDay or secondOfDay fields for example.
The new LocalTime
class removes this restriction.
Calculations on TimeOfDay are performed using a Chronology
.
This chronology is set to be in the UTC time zone for all calculations.
Each individual field can be queried in two ways:
getHourOfDay()
hourOfDay().get()
hourOfDay().get()
hourOfDay().getAsText()
hourOfDay().getAsShortText()
hourOfDay().getMaximumValue()
hourOfDay().addToCopy()
hourOfDay().setCopy()
TimeOfDay is thread-safe and immutable, provided that the Chronology is as well. All standard Chronology classes supplied are thread-safe and immutable.
Nested Class Summary | |
static class |
TimeOfDay.Property
Deprecated. Use LocalTime which has a much better internal implementation |
Field Summary | |
static int |
HOUR_OF_DAY
Deprecated. The index of the hourOfDay field in the field array |
static TimeOfDay |
MIDNIGHT
Deprecated. Constant for midnight. |
static int |
MILLIS_OF_SECOND
Deprecated. The index of the millisOfSecond field in the field array |
static int |
MINUTE_OF_HOUR
Deprecated. The index of the minuteOfHour field in the field array |
static int |
SECOND_OF_MINUTE
Deprecated. The index of the secondOfMinute field in the field array |
Constructor Summary | |
TimeOfDay()
Deprecated. Constructs a TimeOfDay with the current time, using ISOChronology in the default zone to extract the fields. |
|
TimeOfDay(Chronology chronology)
Deprecated. Constructs a TimeOfDay with the current time, using the specified chronology and zone to extract the fields. |
|
TimeOfDay(DateTimeZone zone)
Deprecated. Constructs a TimeOfDay with the current time, using ISOChronology in the specified zone to extract the fields. |
|
TimeOfDay(int hourOfDay,
int minuteOfHour)
Deprecated. Constructs a TimeOfDay with specified hour and minute and zero seconds and milliseconds using ISOChronology in the default zone. |
|
TimeOfDay(int hourOfDay,
int minuteOfHour,
Chronology chronology)
Deprecated. Constructs a TimeOfDay with specified hour and minute and zero seconds and milliseconds. |
|
TimeOfDay(int hourOfDay,
int minuteOfHour,
int secondOfMinute)
Deprecated. Constructs a TimeOfDay with specified time field values and zero milliseconds using ISOChronology in the default zone. |
|
TimeOfDay(int hourOfDay,
int minuteOfHour,
int secondOfMinute,
Chronology chronology)
Deprecated. Constructs a TimeOfDay with specified time field values and zero milliseconds. |
|
TimeOfDay(int hourOfDay,
int minuteOfHour,
int secondOfMinute,
int millisOfSecond)
Deprecated. Constructs a TimeOfDay with specified time field values using ISOChronology in the default zone. |
|
TimeOfDay(int hourOfDay,
int minuteOfHour,
int secondOfMinute,
int millisOfSecond,
Chronology chronology)
Deprecated. Constructs a TimeOfDay with specified time field values and chronology. |
|
TimeOfDay(long instant)
Deprecated. Constructs a TimeOfDay extracting the partial fields from the specified milliseconds using the ISOChronology in the default zone. |
|
TimeOfDay(long instant,
Chronology chronology)
Deprecated. Constructs a TimeOfDay extracting the partial fields from the specified milliseconds using the chronology provided. |
|
TimeOfDay(Object instant)
Deprecated. Constructs a TimeOfDay from an Object that represents a time. |
|
TimeOfDay(Object instant,
Chronology chronology)
Deprecated. Constructs a TimeOfDay from an Object that represents a time, using the specified chronology. |
Method Summary | |
static TimeOfDay |
fromCalendarFields(Calendar calendar)
Deprecated. Constructs a TimeOfDay from a java.util.Calendar
using exactly the same field values avoiding any time zone effects. |
static TimeOfDay |
fromDateFields(Date date)
Deprecated. Constructs a TimeOfDay from a java.util.Date
using exactly the same field values avoiding any time zone effects. |
static TimeOfDay |
fromMillisOfDay(long millisOfDay)
Deprecated. Constructs a TimeOfDay from the specified millis of day using the ISO chronology. |
static TimeOfDay |
fromMillisOfDay(long millisOfDay,
Chronology chrono)
Deprecated. Constructs a TimeOfDay from the specified millis of day using the specified chronology. |
DateTimeFieldType |
getFieldType(int index)
Deprecated. Gets the field type at the specified index. |
DateTimeFieldType[] |
getFieldTypes()
Deprecated. Gets an array of the field type of each of the fields that this partial supports. |
int |
getHourOfDay()
Deprecated. Get the hour of day (0-23) field value. |
int |
getMillisOfSecond()
Deprecated. Get the millis of second field value. |
int |
getMinuteOfHour()
Deprecated. Get the minute of hour field value. |
int |
getSecondOfMinute()
Deprecated. Get the second of minute field value. |
TimeOfDay.Property |
hourOfDay()
Deprecated. Get the hour of day field property which provides access to advanced functionality. |
TimeOfDay.Property |
millisOfSecond()
Deprecated. Get the millis of second property which provides access to advanced functionality. |
TimeOfDay |
minus(ReadablePeriod period)
Deprecated. Returns a copy of this time with the specified period taken away, wrapping to what would be a new day if required. |
TimeOfDay |
minusHours(int hours)
Deprecated. Returns a copy of this time minus the specified number of hours. |
TimeOfDay |
minusMillis(int millis)
Deprecated. Returns a copy of this time minus the specified number of millis. |
TimeOfDay |
minusMinutes(int minutes)
Deprecated. Returns a copy of this time minus the specified number of minutes. |
TimeOfDay |
minusSeconds(int seconds)
Deprecated. Returns a copy of this time minus the specified number of seconds. |
TimeOfDay.Property |
minuteOfHour()
Deprecated. Get the minute of hour field property which provides access to advanced functionality. |
TimeOfDay |
plus(ReadablePeriod period)
Deprecated. Returns a copy of this time with the specified period added, wrapping to what would be a new day if required. |
TimeOfDay |
plusHours(int hours)
Deprecated. Returns a copy of this time plus the specified number of hours. |
TimeOfDay |
plusMillis(int millis)
Deprecated. Returns a copy of this time plus the specified number of millis. |
TimeOfDay |
plusMinutes(int minutes)
Deprecated. Returns a copy of this time plus the specified number of minutes. |
TimeOfDay |
plusSeconds(int seconds)
Deprecated. Returns a copy of this time plus the specified number of seconds. |
TimeOfDay.Property |
property(DateTimeFieldType type)
Deprecated. Gets the property object for the specified type, which contains many useful methods. |
TimeOfDay.Property |
secondOfMinute()
Deprecated. Get the second of minute field property which provides access to advanced functionality. |
int |
size()
Deprecated. Gets the number of fields in this partial. |
DateTime |
toDateTimeToday()
Deprecated. Converts this partial to a full datetime using the default time zone setting the time fields from this instance and the date fields from the current time. |
DateTime |
toDateTimeToday(DateTimeZone zone)
Deprecated. Converts this partial to a full datetime using the specified time zone setting the time fields from this instance and the date fields from the current time. |
LocalTime |
toLocalTime()
Deprecated. Converts this object to a LocalTime with the same time and chronology. |
String |
toString()
Deprecated. Output the time in the ISO8601 format THH:mm:ss.SSS. |
TimeOfDay |
withChronologyRetainFields(Chronology newChronology)
Deprecated. Returns a copy of this time with the specified chronology. |
TimeOfDay |
withField(DateTimeFieldType fieldType,
int value)
Deprecated. Returns a copy of this time with the specified field set to a new value. |
TimeOfDay |
withFieldAdded(DurationFieldType fieldType,
int amount)
Deprecated. Returns a copy of this time with the value of the specified field increased, wrapping to what would be a new day if required. |
TimeOfDay |
withHourOfDay(int hour)
Deprecated. Returns a copy of this time with the hour of day field updated. |
TimeOfDay |
withMillisOfSecond(int millis)
Deprecated. Returns a copy of this time with the millis of second field updated. |
TimeOfDay |
withMinuteOfHour(int minute)
Deprecated. Returns a copy of this time with the minute of hour field updated. |
TimeOfDay |
withPeriodAdded(ReadablePeriod period,
int scalar)
Deprecated. Returns a copy of this time with the specified period added, wrapping to what would be a new day if required. |
TimeOfDay |
withSecondOfMinute(int second)
Deprecated. Returns a copy of this time with the second of minute field updated. |
Methods inherited from class org.joda.time.base.BasePartial |
getChronology, getValue, getValues, toString, toString |
Methods inherited from class org.joda.time.base.AbstractPartial |
compareTo, equals, get, getField, getFields, hashCode, indexOf, isAfter, isBefore, isEqual, isSupported, toDateTime, toString |
Methods inherited from class java.lang.Object |
getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface org.joda.time.ReadablePartial |
equals, get, getChronology, getField, getValue, hashCode, isSupported, toDateTime |
Field Detail |
public static final TimeOfDay MIDNIGHT
public static final int HOUR_OF_DAY
public static final int MINUTE_OF_HOUR
public static final int SECOND_OF_MINUTE
public static final int MILLIS_OF_SECOND
Constructor Detail |
public TimeOfDay()
The constructor uses the default time zone, resulting in the local time being initialised. Once the constructor is complete, all further calculations are performed without reference to a timezone (by switching to UTC).
public TimeOfDay(DateTimeZone zone)
The constructor uses the specified time zone to obtain the current time. Once the constructor is complete, all further calculations are performed without reference to a timezone (by switching to UTC).
zone
- the zone to use, null means default zonepublic TimeOfDay(Chronology chronology)
The constructor uses the time zone of the chronology specified. Once the constructor is complete, all further calculations are performed without reference to a timezone (by switching to UTC).
chronology
- the chronology, null means ISOChronology in the default zonepublic TimeOfDay(long instant)
The constructor uses the default time zone, resulting in the local time being initialised. Once the constructor is complete, all further calculations are performed without reference to a timezone (by switching to UTC).
instant
- the milliseconds from 1970-01-01T00:00:00Zpublic TimeOfDay(long instant, Chronology chronology)
The constructor uses the time zone of the chronology specified. Once the constructor is complete, all further calculations are performed without reference to a timezone (by switching to UTC).
instant
- the milliseconds from 1970-01-01T00:00:00Zchronology
- the chronology, null means ISOChronology in the default zonepublic TimeOfDay(Object instant)
The recognised object types are defined in
ConverterManager
and
include ReadableInstant, String, Calendar and Date.
The String formats are described by ISODateTimeFormat.timeParser()
.
The chronology used will be derived from the object, defaulting to ISO.
NOTE: Prior to v1.3 the string format was described by
ISODateTimeFormat.dateTimeParser()
. Dates are now rejected.
instant
- the datetime object, null means now
IllegalArgumentException
- if the instant is invalidpublic TimeOfDay(Object instant, Chronology chronology)
The recognised object types are defined in
ConverterManager
and
include ReadableInstant, String, Calendar and Date.
The String formats are described by ISODateTimeFormat.timeParser()
.
The constructor uses the time zone of the chronology specified. Once the constructor is complete, all further calculations are performed without reference to a timezone (by switching to UTC). The specified chronology overrides that of the object.
NOTE: Prior to v1.3 the string format was described by
ISODateTimeFormat.dateTimeParser()
. Dates are now rejected.
instant
- the datetime object, null means nowchronology
- the chronology, null means ISO default
IllegalArgumentException
- if the instant is invalidpublic TimeOfDay(int hourOfDay, int minuteOfHour)
ISOChronology
in the default zone.
The constructor uses the no time zone initialising the fields as provided. Once the constructor is complete, all further calculations are performed without reference to a timezone (by switching to UTC).
hourOfDay
- the hour of the dayminuteOfHour
- the minute of the hourpublic TimeOfDay(int hourOfDay, int minuteOfHour, Chronology chronology)
The constructor uses the time zone of the chronology specified. Once the constructor is complete, all further calculations are performed without reference to a timezone (by switching to UTC).
hourOfDay
- the hour of the dayminuteOfHour
- the minute of the hourchronology
- the chronology, null means ISOChronology in the default zonepublic TimeOfDay(int hourOfDay, int minuteOfHour, int secondOfMinute)
ISOChronology
in the default zone.
The constructor uses the no time zone initialising the fields as provided. Once the constructor is complete, all further calculations are performed without reference to a timezone (by switching to UTC).
hourOfDay
- the hour of the dayminuteOfHour
- the minute of the hoursecondOfMinute
- the second of the minutepublic TimeOfDay(int hourOfDay, int minuteOfHour, int secondOfMinute, Chronology chronology)
The constructor uses the time zone of the chronology specified. Once the constructor is complete, all further calculations are performed without reference to a timezone (by switching to UTC).
hourOfDay
- the hour of the dayminuteOfHour
- the minute of the hoursecondOfMinute
- the second of the minutechronology
- the chronology, null means ISOChronology in the default zonepublic TimeOfDay(int hourOfDay, int minuteOfHour, int secondOfMinute, int millisOfSecond)
ISOChronology
in the default zone.
The constructor uses the no time zone initialising the fields as provided. Once the constructor is complete, all further calculations are performed without reference to a timezone (by switching to UTC).
hourOfDay
- the hour of the dayminuteOfHour
- the minute of the hoursecondOfMinute
- the second of the minutemillisOfSecond
- the millisecond of the secondpublic TimeOfDay(int hourOfDay, int minuteOfHour, int secondOfMinute, int millisOfSecond, Chronology chronology)
The constructor uses the time zone of the chronology specified. Once the constructor is complete, all further calculations are performed without reference to a timezone (by switching to UTC).
hourOfDay
- the hour of the dayminuteOfHour
- the minute of the hoursecondOfMinute
- the second of the minutemillisOfSecond
- the millisecond of the secondchronology
- the chronology, null means ISOChronology in the default zoneMethod Detail |
public static TimeOfDay fromCalendarFields(Calendar calendar)
java.util.Calendar
using exactly the same field values avoiding any time zone effects.
Each field is queried from the Calendar and assigned to the TimeOfDay. This is useful to ensure that the field values are the same in the created TimeOfDay no matter what the time zone is. For example, if the Calendar states that the time is 04:29, then the created TimeOfDay will always have the time 04:29 irrespective of time zone issues.
This factory method ignores the type of the calendar and always creates a TimeOfDay with ISO chronology.
calendar
- the Calendar to extract fields from
IllegalArgumentException
- if the calendar is null
IllegalArgumentException
- if the time is invalid for the ISO chronologypublic static TimeOfDay fromDateFields(Date date)
java.util.Date
using exactly the same field values avoiding any time zone effects.
Each field is queried from the Date and assigned to the TimeOfDay. This is useful to ensure that the field values are the same in the created TimeOfDay no matter what the time zone is. For example, if the Calendar states that the time is 04:29, then the created TimeOfDay will always have the time 04:29 irrespective of time zone issues.
This factory method always creates a TimeOfDay with ISO chronology.
date
- the Date to extract fields from
IllegalArgumentException
- if the calendar is null
IllegalArgumentException
- if the date is invalid for the ISO chronologypublic static TimeOfDay fromMillisOfDay(long millisOfDay)
The millisOfDay value may exceed the number of millis in one day, but additional days will be ignored. This method uses the UTC time zone internally.
millisOfDay
- the number of milliseconds into a day to convertpublic static TimeOfDay fromMillisOfDay(long millisOfDay, Chronology chrono)
The millisOfDay value may exceed the number of millis in one day, but additional days will be ignored. This method uses the UTC time zone internally.
millisOfDay
- the number of milliseconds into a day to convertchrono
- the chronology, null means ISO chronologypublic int size()
size
in interface ReadablePartial
public DateTimeFieldType getFieldType(int index)
getFieldType
in interface ReadablePartial
getFieldType
in class AbstractPartial
index
- the index to retrieve
IndexOutOfBoundsException
- if the index is invalidpublic DateTimeFieldType[] getFieldTypes()
The fields are returned largest to smallest, Hour, Minute, Second, Millis.
getFieldTypes
in class AbstractPartial
public TimeOfDay withChronologyRetainFields(Chronology newChronology)
This method retains the values of the fields, thus the result will typically refer to a different instant.
The time zone of the specified chronology is ignored, as TimeOfDay operates without a time zone.
newChronology
- the new chronology, null means ISO
IllegalArgumentException
- if the values are invalid for the new chronologypublic TimeOfDay withField(DateTimeFieldType fieldType, int value)
For example, if the field type is minuteOfHour
then the day
would be changed in the returned instance.
These three lines are equivalent:
TimeOfDay updated = tod.withField(DateTimeFieldType.minuteOfHour(), 6); TimeOfDay updated = tod.minuteOfHour().setCopy(6); TimeOfDay updated = tod.property(DateTimeFieldType.minuteOfHour()).setCopy(6);
fieldType
- the field type to set, not nullvalue
- the value to set
IllegalArgumentException
- if the value is null or invalidpublic TimeOfDay withFieldAdded(DurationFieldType fieldType, int amount)
If the addition is zero, then this
is returned.
These three lines are equivalent:
TimeOfDay added = tod.withFieldAdded(DurationFieldType.minutes(), 6); TimeOfDay added = tod.plusMinutes(6); TimeOfDay added = tod.minuteOfHour().addToCopy(6);
fieldType
- the field type to add to, not nullamount
- the amount to add
IllegalArgumentException
- if the value is null or invalid
ArithmeticException
- if the new datetime exceeds the capacitypublic TimeOfDay withPeriodAdded(ReadablePeriod period, int scalar)
If the addition is zero, then this
is returned.
Fields in the period that aren't present in the partial are ignored.
This method is typically used to add multiple copies of complex
period instances. Adding one field is best achieved using methods
like withFieldAdded(DurationFieldType, int)
or plusHours(int)
.
period
- the period to add to this one, null means zeroscalar
- the amount of times to add, such as -1 to subtract once
ArithmeticException
- if the new datetime exceeds the capacitypublic TimeOfDay plus(ReadablePeriod period)
If the amount is zero or null, then this
is returned.
This method is typically used to add complex period instances.
Adding one field is best achieved using methods
like plusHours(int)
.
period
- the duration to add to this one, null means zero
ArithmeticException
- if the new datetime exceeds the capacity of a longpublic TimeOfDay plusHours(int hours)
This time instance is immutable and unaffected by this method call.
The following three lines are identical in effect:
TimeOfDay added = dt.plusHours(6); TimeOfDay added = dt.plus(Period.hours(6)); TimeOfDay added = dt.withFieldAdded(DurationFieldType.hours(), 6);
hours
- the amount of hours to add, may be negative
public TimeOfDay plusMinutes(int minutes)
This time instance is immutable and unaffected by this method call.
The following three lines are identical in effect:
TimeOfDay added = dt.plusMinutes(6); TimeOfDay added = dt.plus(Period.minutes(6)); TimeOfDay added = dt.withFieldAdded(DurationFieldType.minutes(), 6);
minutes
- the amount of minutes to add, may be negative
public TimeOfDay plusSeconds(int seconds)
This time instance is immutable and unaffected by this method call.
The following three lines are identical in effect:
TimeOfDay added = dt.plusSeconds(6); TimeOfDay added = dt.plus(Period.seconds(6)); TimeOfDay added = dt.withFieldAdded(DurationFieldType.seconds(), 6);
seconds
- the amount of seconds to add, may be negative
public TimeOfDay plusMillis(int millis)
This time instance is immutable and unaffected by this method call.
The following three lines are identical in effect:
TimeOfDay added = dt.plusMillis(6); TimeOfDay added = dt.plus(Period.millis(6)); TimeOfDay added = dt.withFieldAdded(DurationFieldType.millis(), 6);
millis
- the amount of millis to add, may be negative
public TimeOfDay minus(ReadablePeriod period)
If the amount is zero or null, then this
is returned.
This method is typically used to subtract complex period instances.
Subtracting one field is best achieved using methods
like minusHours(int)
.
period
- the period to reduce this instant by
ArithmeticException
- if the new time exceeds capacitypublic TimeOfDay minusHours(int hours)
This time instance is immutable and unaffected by this method call.
The following three lines are identical in effect:
TimeOfDay subtracted = dt.minusHours(6); TimeOfDay subtracted = dt.minus(Period.hours(6)); TimeOfDay subtracted = dt.withFieldAdded(DurationFieldType.hours(), -6);
hours
- the amount of hours to subtract, may be negative
public TimeOfDay minusMinutes(int minutes)
This time instance is immutable and unaffected by this method call.
The following three lines are identical in effect:
TimeOfDay subtracted = dt.minusMinutes(6); TimeOfDay subtracted = dt.minus(Period.minutes(6)); TimeOfDay subtracted = dt.withFieldAdded(DurationFieldType.minutes(), -6);
minutes
- the amount of minutes to subtract, may be negative
public TimeOfDay minusSeconds(int seconds)
This time instance is immutable and unaffected by this method call.
The following three lines are identical in effect:
TimeOfDay subtracted = dt.minusSeconds(6); TimeOfDay subtracted = dt.minus(Period.seconds(6)); TimeOfDay subtracted = dt.withFieldAdded(DurationFieldType.seconds(), -6);
seconds
- the amount of seconds to subtract, may be negative
public TimeOfDay minusMillis(int millis)
This time instance is immutable and unaffected by this method call.
The following three lines are identical in effect:
TimeOfDay subtracted = dt.minusMillis(6); TimeOfDay subtracted = dt.minus(Period.millis(6)); TimeOfDay subtracted = dt.withFieldAdded(DurationFieldType.millis(), -6);
millis
- the amount of millis to subtract, may be negative
public TimeOfDay.Property property(DateTimeFieldType type)
type
- the field type to get the property for
IllegalArgumentException
- if the field is null or unsupportedpublic LocalTime toLocalTime()
public DateTime toDateTimeToday()
public DateTime toDateTimeToday(DateTimeZone zone)
This method uses the chronology from this instance plus the time zone specified.
zone
- the zone to use, null means default
public int getHourOfDay()
public int getMinuteOfHour()
public int getSecondOfMinute()
public int getMillisOfSecond()
public TimeOfDay withHourOfDay(int hour)
TimeOfDay is immutable, so there are no set methods. Instead, this method returns a new instance with the value of hour of day changed.
hour
- the hour of day to set
IllegalArgumentException
- if the value is invalidpublic TimeOfDay withMinuteOfHour(int minute)
TimeOfDay is immutable, so there are no set methods. Instead, this method returns a new instance with the value of minute of hour changed.
minute
- the minute of hour to set
IllegalArgumentException
- if the value is invalidpublic TimeOfDay withSecondOfMinute(int second)
TimeOfDay is immutable, so there are no set methods. Instead, this method returns a new instance with the value of second of minute changed.
second
- the second of minute to set
IllegalArgumentException
- if the value is invalidpublic TimeOfDay withMillisOfSecond(int millis)
TimeOfDay is immutable, so there are no set methods. Instead, this method returns a new instance with the value of millis of second changed.
millis
- the millis of second to set
IllegalArgumentException
- if the value is invalidpublic TimeOfDay.Property hourOfDay()
public TimeOfDay.Property minuteOfHour()
public TimeOfDay.Property secondOfMinute()
public TimeOfDay.Property millisOfSecond()
public String toString()
toString
in interface ReadablePartial
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |