Joda Time API

org.joda.time
Class Instant

java.lang.Object
  |
  +--org.joda.time.AbstractInstant
        |
        +--org.joda.time.Instant
All Implemented Interfaces:
java.lang.Comparable, ReadableInstant, java.io.Serializable

public final class Instant
extends AbstractInstant
implements ReadableInstant

Instant is the standard implementation of a fully immutable instant in time. It holds the instant as milliseconds from the Java Epoch of 1970-01-01T00:00:00Z.

There is no concept of a calendar system, chronology or time zone. In a fully internationalized program, methods should accept the ReadableInstant interface as input and return Instant objects.

Since:
1.0
Author:
Stephen Colebourne
See Also:
Serialized Form

Constructor Summary
Instant()
          Constructor that sets the time to be the current time from the system clock.
Instant(java.util.Calendar calendar)
          Constructor that takes a Calendar.
Instant(java.util.Date date)
          Constructor that takes a Date.
Instant(long millis)
          Constructor that takes milliseconds from 1970-01-01T00:00:00Z.
Instant(ReadableInstant instant)
          Constructor that takes a ReadableInstant.
Instant(java.lang.String str)
          Constructor that parses an ISO formatted string.
 
Method Summary
protected  ReadableInstant create(long millis, Chronology chrono)
          Creates a new instance of this class.
 Chronology getChronology()
          Gets the chronology of the instant, which is null.
 long getMillis()
          Gets the milliseconds of the instant.
 java.lang.String toString()
          Output the date time in ISO8601 format.
 
Methods inherited from class org.joda.time.AbstractInstant
compareTo, equals, get, getDateTimeZone, hashCode, isAfter, isBefore, isEqual, toCalendar, toCopy, toCopy, toDate, toGregorianCalendar, toInstant
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.joda.time.ReadableInstant
compareTo, equals, get, getDateTimeZone, hashCode, isAfter, isBefore, isEqual, toCopy, toCopy, toInstant
 

Constructor Detail

Instant

public Instant()
Constructor that sets the time to be the current time from the system clock.


Instant

public Instant(long millis)
Constructor that takes milliseconds from 1970-01-01T00:00:00Z.

Parameters:
millis - the milliseconds

Instant

public Instant(ReadableInstant instant)
Constructor that takes a ReadableInstant.

Parameters:
instant - the ReadableInstant
Throws:
java.lang.IllegalArgumentException - if the instant is null

Instant

public Instant(java.util.Date date)
Constructor that takes a Date.

Parameters:
date - the Date
Throws:
java.lang.IllegalArgumentException - if the date is null

Instant

public Instant(java.util.Calendar calendar)
Constructor that takes a Calendar.

Parameters:
calendar - the Calendar
Throws:
java.lang.IllegalArgumentException - if the calendar is null

Instant

public Instant(java.lang.String str)
        throws java.text.ParseException
Constructor that parses an ISO formatted string.

Parameters:
str - the string
Throws:
java.lang.IllegalArgumentException - if the string is null
java.text.ParseException - if the string is incorrectly formatted
Method Detail

create

protected ReadableInstant create(long millis,
                                 Chronology chrono)
Creates a new instance of this class.

The returned object will be a new instance of the implementation. Immutable subclasses may return this if appropriate.

Specified by:
create in class AbstractInstant
Parameters:
millis - the new millis, from 1970-01-01T00:00:00Z
chrono - the new chronology
Returns:
a new instance of this class
Throws:
java.lang.IllegalArgumentException - if the chronology is null

getMillis

public final long getMillis()
Gets the milliseconds of the instant.

Specified by:
getMillis in interface ReadableInstant
Returns:
the number of milliseconds since 1970-01-01T00:00:00Z

getChronology

public final Chronology getChronology()
Gets the chronology of the instant, which is null.

The Chronology provides conversion from the millisecond value to meaningful fields in a particular calendar system. This class represents a chronology free view of time, so this method returns null.

Specified by:
getChronology in interface ReadableInstant
Returns:
null

toString

public final java.lang.String toString()
Output the date time in ISO8601 format.

ISO8601 is deliberately used here so that the resulting string can be re-parsed by the constructor.

Specified by:
toString in interface ReadableInstant
Specified by:
toString in class AbstractInstant
Returns:
ISO8601 date formatted string

Joda Time API

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