Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.joda.time
Class TimeOfDay  view TimeOfDay download TimeOfDay.java

java.lang.Object
  extended byorg.joda.time.base.AbstractPartial
      extended byorg.joda.time.base.BasePartial
          extended byorg.joda.time.TimeOfDay
All Implemented Interfaces:
java.lang.Comparable, ReadablePartial, java.io.Serializable

public final class TimeOfDay
extends org.joda.time.base.BasePartial
implements ReadablePartial, java.io.Serializable

TimeOfDay is an immutable partial supporting the hour, minute, second and millisecond fields.

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:

The second technique also provides access to other useful methods on the field:

TimeOfDay is thread-safe and immutable, provided that the Chronology is as well. All standard Chronology classes supplied are thread-safe and immutable.

Since:
1.0

Nested Class Summary
static class TimeOfDay.Property
          The property class for TimeOfDay.
 
Field Summary
private static DateTimeFieldType[] FIELD_TYPES
          The singleton set of field types
static int HOUR_OF_DAY
          The index of the hourOfDay field in the field array
static TimeOfDay MIDNIGHT
          Constant for midnight.
static int MILLIS_OF_SECOND
          The index of the millisOfSecond field in the field array
static int MINUTE_OF_HOUR
          The index of the minuteOfHour field in the field array
static int SECOND_OF_MINUTE
          The index of the secondOfMinute field in the field array
private static long serialVersionUID
          Serialization version
 
Fields inherited from class org.joda.time.base.BasePartial
 
Constructor Summary
  TimeOfDay()
          Constructs a TimeOfDay with the current time, using ISOChronology in the default zone to extract the fields.
  TimeOfDay(Chronology chronology)
          Constructs a TimeOfDay with the current time, using the specified chronology and zone to extract the fields.
  TimeOfDay(DateTimeZone zone)
          Constructs a TimeOfDay with the current time, using ISOChronology in the specified zone to extract the fields.
  TimeOfDay(int hourOfDay, int minuteOfHour)
          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)
          Constructs a TimeOfDay with specified hour and minute and zero seconds and milliseconds.
  TimeOfDay(int hourOfDay, int minuteOfHour, int secondOfMinute)
          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)
          Constructs a TimeOfDay with specified time field values and zero milliseconds.
  TimeOfDay(int hourOfDay, int minuteOfHour, int secondOfMinute, int millisOfSecond)
          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)
          Constructs a TimeOfDay with specified time field values and chronology.
  TimeOfDay(long instant)
          Constructs a TimeOfDay extracting the partial fields from the specified milliseconds using the ISOChronology in the default zone.
  TimeOfDay(long instant, Chronology chronology)
          Constructs a TimeOfDay extracting the partial fields from the specified milliseconds using the chronology provided.
  TimeOfDay(java.lang.Object instant)
          Constructs a TimeOfDay from an Object that represents a time.
  TimeOfDay(java.lang.Object instant, Chronology chronology)
          Constructs a TimeOfDay from an Object that represents a time, using the specified chronology.
(package private) TimeOfDay(TimeOfDay partial, Chronology chrono)
          Constructs a TimeOfDay with values from this instance and a new chronology.
(package private) TimeOfDay(TimeOfDay partial, int[] values)
          Constructs a TimeOfDay with chronology from this instance and new values.
 
Method Summary
static TimeOfDay fromMillisOfDay(long millisOfDay)
          Constructs a TimeOfDay from the specified millis of day using the ISO chronology.
static TimeOfDay fromMillisOfDay(long millisOfDay, Chronology chrono)
          Constructs a TimeOfDay from the specified millis of day using the specified chronology.
protected  DateTimeField getField(int index, Chronology chrono)
          Gets the field for a specific index in the chronology specified.
 DateTimeFieldType getFieldType(int index)
          Gets the field type at the specified index.
 DateTimeFieldType[] getFieldTypes()
          Gets an array of the field type of each of the fields that this partial supports.
 int getHourOfDay()
          Get the hour of day (0-23) field value.
 int getMillisOfSecond()
          Get the millis of second field value.
 int getMinuteOfHour()
          Get the minute of hour field value.
 int getSecondOfMinute()
          Get the second of minute field value.
 TimeOfDay.Property hourOfDay()
          Get the hour of day (0-23) field property
 TimeOfDay.Property millisOfSecond()
          Get the millis of second property
 TimeOfDay minus(ReadablePeriod period)
          Gets a copy of this instance with the specified period take away, wrapping to what would be a new day if required.
 TimeOfDay minusHours(int hours)
          Returns a new time minus the specified number of hours.
 TimeOfDay minusMillis(int millis)
          Returns a new time minus the specified number of millis.
 TimeOfDay minusMinutes(int minutes)
          Returns a new time minus the specified number of minutes.
 TimeOfDay minusSeconds(int seconds)
          Returns a new time minus the specified number of seconds.
 TimeOfDay.Property minuteOfHour()
          Get the minute of hour field property
 TimeOfDay plus(ReadablePeriod period)
          Gets a copy of this instance with the specified period added, wrapping to what would be a new day if required.
 TimeOfDay plusHours(int hours)
          Returns a new time plus the specified number of hours.
 TimeOfDay plusMillis(int millis)
          Returns a new time plus the specified number of millis.
 TimeOfDay plusMinutes(int minutes)
          Returns a new time plus the specified number of minutes.
 TimeOfDay plusSeconds(int seconds)
          Returns a new time plus the specified number of seconds.
 TimeOfDay.Property property(DateTimeFieldType type)
          Gets the property object for the specified type, which contains many useful methods.
 TimeOfDay.Property secondOfMinute()
          Get the second of minute field property
 int size()
          Gets the number of fields in this partial.
 DateTime toDateTimeToday()
          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)
          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.
 java.lang.String toString()
          Output the time in the ISO8601 format THH:mm:ss.SSS.
 TimeOfDay withChronologyRetainFields(Chronology newChronology)
          Creates a new TimeOfDay instance with the specified chronology.
 TimeOfDay withField(DateTimeFieldType fieldType, int value)
          Gets a copy of this time with the specified field set to a new value.
 TimeOfDay withFieldAdded(DurationFieldType fieldType, int amount)
          Gets a copy of this time with the value of the specified field increased, wrapping to what would be a new day if required.
 TimeOfDay withPeriodAdded(ReadablePeriod period, int scalar)
          Gets a copy of this date with the specified period added, wrapping to what would be a new day if required.
 
Methods inherited from class org.joda.time.base.BasePartial
getChronology, getValue, getValues, setValue, setValues, toString, toString
 
Methods inherited from class org.joda.time.base.AbstractPartial
compareTo, equals, get, getField, getFields, hashCode, indexOf, indexOf, indexOfSupported, indexOfSupported, isAfter, isBefore, isEqual, isSupported, toDateTime, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.joda.time.ReadablePartial
equals, get, getChronology, getField, getValue, hashCode, isSupported, toDateTime
 

Field Detail

serialVersionUID

private static final long serialVersionUID
Serialization version

See Also:
Constant Field Values

FIELD_TYPES

private static final DateTimeFieldType[] FIELD_TYPES
The singleton set of field types


MIDNIGHT

public static final TimeOfDay MIDNIGHT
Constant for midnight.


HOUR_OF_DAY

public static final int HOUR_OF_DAY
The index of the hourOfDay field in the field array

See Also:
Constant Field Values

MINUTE_OF_HOUR

public static final int MINUTE_OF_HOUR
The index of the minuteOfHour field in the field array

See Also:
Constant Field Values

SECOND_OF_MINUTE

public static final int SECOND_OF_MINUTE
The index of the secondOfMinute field in the field array

See Also:
Constant Field Values

MILLIS_OF_SECOND

public static final int MILLIS_OF_SECOND
The index of the millisOfSecond field in the field array

See Also:
Constant Field Values
Constructor Detail

TimeOfDay

public TimeOfDay()
Constructs a TimeOfDay with the current time, using ISOChronology in the default zone to extract the fields.

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).


TimeOfDay

public TimeOfDay(DateTimeZone zone)
Constructs a TimeOfDay with the current time, using ISOChronology in the specified zone to extract the fields.

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).

Since:
1.1

TimeOfDay

public TimeOfDay(Chronology chronology)
Constructs a TimeOfDay with the current time, using the specified chronology and zone to extract the fields.

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).


TimeOfDay

public TimeOfDay(long instant)
Constructs a TimeOfDay extracting the partial fields from the specified milliseconds using the ISOChronology in the default zone.

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).


TimeOfDay

public TimeOfDay(long instant,
                 Chronology chronology)
Constructs a TimeOfDay extracting the partial fields from the specified milliseconds using the chronology provided.

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).


TimeOfDay

public TimeOfDay(java.lang.Object instant)
Constructs a TimeOfDay from an Object that represents a time.

The recognised object types are defined in ConverterManager and include ReadableInstant, String, Calendar and Date.

The string format must begin with a 'T' to be recognised, such as 'T10:20'.

The chronology used will be derived from the object, defaulting to ISO.


TimeOfDay

public TimeOfDay(java.lang.Object instant,
                 Chronology chronology)
Constructs a TimeOfDay from an Object that represents a time, using the specified chronology.

The recognised object types are defined in ConverterManager and include ReadableInstant, String, Calendar and Date.

The string format must begin with a 'T' to be recognised, such as 'T10:20'.

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.


TimeOfDay

public TimeOfDay(int hourOfDay,
                 int minuteOfHour)
Constructs a TimeOfDay with specified hour and minute and zero seconds and milliseconds using 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).


TimeOfDay

public TimeOfDay(int hourOfDay,
                 int minuteOfHour,
                 Chronology chronology)
Constructs a TimeOfDay with specified hour and minute and zero seconds and milliseconds.

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).


TimeOfDay

public TimeOfDay(int hourOfDay,
                 int minuteOfHour,
                 int secondOfMinute)
Constructs a TimeOfDay with specified time field values and zero milliseconds using 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).


TimeOfDay

public TimeOfDay(int hourOfDay,
                 int minuteOfHour,
                 int secondOfMinute,
                 Chronology chronology)
Constructs a TimeOfDay with specified time field values and zero milliseconds.

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).


TimeOfDay

public TimeOfDay(int hourOfDay,
                 int minuteOfHour,
                 int secondOfMinute,
                 int millisOfSecond)
Constructs a TimeOfDay with specified time field values using 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).


TimeOfDay

public TimeOfDay(int hourOfDay,
                 int minuteOfHour,
                 int secondOfMinute,
                 int millisOfSecond,
                 Chronology chronology)
Constructs a TimeOfDay with specified time field values and 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).


TimeOfDay

TimeOfDay(TimeOfDay partial,
          int[] values)
Constructs a TimeOfDay with chronology from this instance and new values.


TimeOfDay

TimeOfDay(TimeOfDay partial,
          Chronology chrono)
Constructs a TimeOfDay with values from this instance and a new chronology.

Method Detail

fromMillisOfDay

public static TimeOfDay fromMillisOfDay(long millisOfDay)
Constructs a TimeOfDay from the specified millis of day using the ISO chronology.

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.


fromMillisOfDay

public static TimeOfDay fromMillisOfDay(long millisOfDay,
                                        Chronology chrono)
Constructs a TimeOfDay from the specified millis of day using the specified chronology.

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.


size

public int size()
Gets the number of fields in this partial.

Specified by:
size in interface ReadablePartial

getField

protected DateTimeField getField(int index,
                                 Chronology chrono)
Gets the field for a specific index in the chronology specified.

This method must not use any instance variables.


getFieldType

public DateTimeFieldType getFieldType(int index)
Gets the field type at the specified index.

Specified by:
getFieldType in interface ReadablePartial

getFieldTypes

public DateTimeFieldType[] getFieldTypes()
Gets an array of the field type of each of the fields that this partial supports.

The fields are returned largest to smallest, Hour, Minute, Second, Millis.


withChronologyRetainFields

public TimeOfDay withChronologyRetainFields(Chronology newChronology)
Creates a new TimeOfDay instance with the specified chronology. This instance is immutable and unaffected by this method call.

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.


withField

public TimeOfDay withField(DateTimeFieldType fieldType,
                           int value)
Gets a copy of this time with the specified field set to a new 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);
 


withFieldAdded

public TimeOfDay withFieldAdded(DurationFieldType fieldType,
                                int amount)
Gets a copy of this time with the value of the specified field increased, wrapping to what would be a new day if required.

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);
 


withPeriodAdded

public TimeOfDay withPeriodAdded(ReadablePeriod period,
                                 int scalar)
Gets a copy of this date with the specified period added, wrapping to what would be a new day if required.

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) 55 or plusHours(int) 55 .


plus

public TimeOfDay plus(ReadablePeriod period)
Gets a copy of this instance with the specified period added, wrapping to what would be a new day if required.

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) 55 .


plusHours

public TimeOfDay plusHours(int hours)
Returns a new time plus the specified number of 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);
 

Since:
1.1

plusMinutes

public TimeOfDay plusMinutes(int minutes)
Returns a new time plus the specified number of 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);
 

Since:
1.1

plusSeconds

public TimeOfDay plusSeconds(int seconds)
Returns a new time plus the specified number of 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);
 

Since:
1.1

plusMillis

public TimeOfDay plusMillis(int millis)
Returns a new time plus the specified number of 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);
 

Since:
1.1

minus

public TimeOfDay minus(ReadablePeriod period)
Gets a copy of this instance with the specified period take away, wrapping to what would be a new day if required.

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) 55 .


minusHours

public TimeOfDay minusHours(int hours)
Returns a new time minus the specified number of 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);
 

Since:
1.1

minusMinutes

public TimeOfDay minusMinutes(int minutes)
Returns a new time minus the specified number of 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);
 

Since:
1.1

minusSeconds

public TimeOfDay minusSeconds(int seconds)
Returns a new time minus the specified number of 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);
 

Since:
1.1

minusMillis

public TimeOfDay minusMillis(int millis)
Returns a new time minus the specified number of 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);
 

Since:
1.1

property

public TimeOfDay.Property property(DateTimeFieldType type)
Gets the property object for the specified type, which contains many useful methods.


toDateTimeToday

public DateTime toDateTimeToday()
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.


toDateTimeToday

public DateTime toDateTimeToday(DateTimeZone zone)
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.

This method uses the chronology from this instance plus the time zone specified.


getHourOfDay

public int getHourOfDay()
Get the hour of day (0-23) field value.


getMinuteOfHour

public int getMinuteOfHour()
Get the minute of hour field value.


getSecondOfMinute

public int getSecondOfMinute()
Get the second of minute field value.


getMillisOfSecond

public int getMillisOfSecond()
Get the millis of second field value.


hourOfDay

public TimeOfDay.Property hourOfDay()
Get the hour of day (0-23) field property


minuteOfHour

public TimeOfDay.Property minuteOfHour()
Get the minute of hour field property


secondOfMinute

public TimeOfDay.Property secondOfMinute()
Get the second of minute field property


millisOfSecond

public TimeOfDay.Property millisOfSecond()
Get the millis of second property


toString

public java.lang.String toString()
Output the time in the ISO8601 format THH:mm:ss.SSS.

Specified by:
toString in interface ReadablePartial