Joda Time API

org.joda.time
Class TimeOnly

java.lang.Object
  |
  +--org.joda.time.AbstractInstant
        |
        +--org.joda.time.TimeOnly
All Implemented Interfaces:
java.lang.Comparable, ReadableInstant, java.io.Serializable
Direct Known Subclasses:
BuddhistTimeOnly, GJTimeOnly, ISOTimeOnly

public class TimeOnly
extends AbstractInstant

TimeOnly is the basic implementation of a time only class supporting chronologies and time zones. It holds the time as milliseconds from the Epoch of 1970-01-01T00:00:00Z. There is no date component - the date is always 1970-01-01.

Each individual field can be queried in two ways:

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

This class is immutable provided that the Chronology is immutable. All Chronology classes supplied are immutable.

Author:
Stephen Colebourne, Brian S O'Neill
See Also:
ISOChronology, ISODateTimeFormat, DateTimeZone.UTC, Serialized Form

Constructor Summary
TimeOnly(java.util.Calendar calendar, Chronology chronology)
          Constructs a TimeOnly from a Calendar.
TimeOnly(Chronology chronology)
          Constructs a TimeOnly to the current time, as reported by the system clock.
TimeOnly(java.util.Date date, Chronology chronology)
          Constructs a TimeOnly from a Date.
TimeOnly(long millis, Chronology chronology)
          Constructs a TimeOnly set to the milliseconds from 1970-01-01T00:00:00Z.
TimeOnly(ReadableInstant instant, Chronology chronology)
          Constructs a TimeOnly from a ReadableInstant.
TimeOnly(java.lang.String str, Chronology chronology)
          Constructs a TimeOnly from an ISO formatted String.
 
Method Summary
 Chronology getChronology()
          Gets the chronology of the time.
 int getHourOfDay()
          Get the hour of day field value.
 long getMillis()
          Gets the milliseconds of the time instant from the Java epoch of 1970-01-01T00:00:00Z.
 int getMillisOfDay()
          Get the millis of day field value.
 int getMillisOfSecond()
          Get the millis of second field value.
 int getMinuteOfDay()
          Get the minute of day field value.
 int getMinuteOfHour()
          Get the minute of hour field value.
 int getSecondOfDay()
          Get the second of day field value.
 int getSecondOfMinute()
          Get the second of minute field value.
 DateTimeFieldProperty hourOfDay()
          Get the hour of day field property.
 DateTimeFieldProperty millisOfDay()
          Get the millis of day property.
 DateTimeFieldProperty millisOfSecond()
          Get the millis of second property.
 DateTimeFieldProperty minuteOfDay()
          Get the minute of day property.
 DateTimeFieldProperty minuteOfHour()
          Get the minute of hour field property.
 DateTimeFieldProperty secondOfDay()
          Get the second of day property.
 DateTimeFieldProperty secondOfMinute()
          Get the second of minute field property.
 java.lang.String toString()
          Output the date time in ISO8601 format (HH:MM:SS.SSSZ).
 
Methods inherited from class org.joda.time.AbstractInstant
compareTo, equals, get, hashCode, isAfter, isBefore, isEqual, toCalendar, toDate, toGregorianCalendar, toInstant
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TimeOnly

public TimeOnly(Chronology chronology)
Constructs a TimeOnly to the current time, as reported by the system clock. If the supplied chronology is null, it defaults to ISO, in the time zone returned by DateTimeZone.getDefault().

Parameters:
chronology - the chronology, null is ISO

TimeOnly

public TimeOnly(long millis,
                Chronology chronology)
Constructs a TimeOnly set to the milliseconds from 1970-01-01T00:00:00Z. If the supplied chronology is null, it defaults to ISO, in the time zone returned by DateTimeZone.getDefault().

Parameters:
millis - the milliseconds
chronology - the chronology, null is ISO

TimeOnly

public TimeOnly(ReadableInstant instant,
                Chronology chronology)
Constructs a TimeOnly from a ReadableInstant. If the supplied chronology is null, it defaults to the chronology of the supplied instant. If that chronology is also null, then the chronology is set to ISO, in the time zone returned by DateTimeZone.getDefault().

Parameters:
instant - the ReadableInstant, must not be null
chronology - the chronology, null means use instant to determine
Throws:
java.lang.IllegalArgumentException - if the instant is null

TimeOnly

public TimeOnly(java.util.Date date,
                Chronology chronology)
Constructs a TimeOnly from a Date. If the supplied chronology is null, it defaults to ISO, in the time zone returned by DateTimeZone.getDefault().

Parameters:
date - the Date, must not be null
chronology - the chronology, null is ISO
Throws:
java.lang.IllegalArgumentException - if the date is null

TimeOnly

public TimeOnly(java.util.Calendar calendar,
                Chronology chronology)
Constructs a TimeOnly from a Calendar.

If the chronology is specified, it is used. If null, the chronology and time zone from the calendar is used. If that cannot be determined, ISOChronology in the default time zone is used.

When converting calendars to chronologies, the constructor is aware of GregorianCalendar and BuddhistCalendar and maps them to the equivalent chronology. Other calendars map to ISOChronology.

Parameters:
calendar - the Calendar, must not be null
chronology - the chronology, null means use calendar to determine
Throws:
java.lang.IllegalArgumentException - if the calendar is null

TimeOnly

public TimeOnly(java.lang.String str,
                Chronology chronology)
         throws java.text.ParseException
Constructs a TimeOnly from an ISO formatted String. If the supplied chronology is null, it defaults to ISO, in the time zone returned by DateTimeZone.getDefault().

Parameters:
str - the string to parse, must not be null
chronology - the chronology, null is ISO
Throws:
java.lang.IllegalArgumentException - if the string is null
java.text.ParseException - if parsing fails
Method Detail

getMillis

public final long getMillis()
Gets the milliseconds of the time instant from the Java epoch of 1970-01-01T00:00:00Z.

Returns:
the number of milliseconds since 1970-01-01T00:00:00Z

getChronology

public final Chronology getChronology()
Gets the chronology of the time.

Returns:
the Chronology that the time is using

getMillisOfSecond

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

Returns:
the millis of second

getMillisOfDay

public final int getMillisOfDay()
Get the millis of day field value.

Returns:
the millis of day

getSecondOfMinute

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

Returns:
the second of minute

getSecondOfDay

public final int getSecondOfDay()
Get the second of day field value.

Returns:
the second of day

getMinuteOfHour

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

Returns:
the minute of hour

getMinuteOfDay

public final int getMinuteOfDay()
Get the minute of day field value.

Returns:
the minute of day

getHourOfDay

public final int getHourOfDay()
Get the hour of day field value.

Returns:
the hour of day

millisOfSecond

public final DateTimeFieldProperty millisOfSecond()
Get the millis of second property.

Returns:
the millis of second property

millisOfDay

public final DateTimeFieldProperty millisOfDay()
Get the millis of day property.

Returns:
the millis of day property

secondOfMinute

public final DateTimeFieldProperty secondOfMinute()
Get the second of minute field property.

Returns:
the second of minute property

secondOfDay

public final DateTimeFieldProperty secondOfDay()
Get the second of day property.

Returns:
the second of day property

minuteOfHour

public final DateTimeFieldProperty minuteOfHour()
Get the minute of hour field property.

Returns:
the minute of hour property

minuteOfDay

public final DateTimeFieldProperty minuteOfDay()
Get the minute of day property.

Returns:
the minute of day property

hourOfDay

public final DateTimeFieldProperty hourOfDay()
Get the hour of day field property.

Returns:
the hour of day property

toString

public final java.lang.String toString()
Output the date time in ISO8601 format (HH:MM:SS.SSSZ).

Specified by:
toString in interface ReadableInstant
Overrides:
toString in class java.lang.Object
Returns:
ISO8601 time formatted string

Joda Time API

Copyright © 2001-2003 Stephen Colebourne. All Rights Reserved.