public final class Timestamp extends java.lang.Object implements java.lang.Comparable<Timestamp>, java.lang.Cloneable
Timestamps preserve precision, meaning the fields that are included, and the significant digits of any fractional second. Only common break points in the values are supported. Any unspecified fields are handled as the start of the new year/month/day.
IonValue
classes, the equals
methods on this class
perform a strict equivalence that observes the precision and local offset
of each timestamp.
This means that it's possible to have two Timestamp
instances that
represent the same point in time but are not equals
.
On the other hand, the compareTo(com.amazon.ion.Timestamp)
methods perform point in time
comparison, ignoring precision and local offset.
Thus the natural comparison method of this class is not
consistent with equals. See the documentation of Comparable
for
further discussion.
To illustrate this distinction, consider the following timestamps. None are
equals(java.lang.Object)
to each other, but any pair will return a zero result from
compareTo(com.amazon.ion.Timestamp)
.
2009T
2009-01T
2009-01-01T
2009-01-01T00:00Z
2009-01-01T00:00:00Z
2009-01-01T00:00:00.0Z
2009-01-01T00:00:00.00Z
2009-01-01T00:00:00.000Z
etc.equals(Timestamp)
,
compareTo(Timestamp)
Modifier and Type | Class and Description |
---|---|
static class |
Timestamp.Precision
The precision of the Timestamp.
|
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_MAXIMUM_DIGITS_TEXT
The default maximum number of digits in the fractional component that will be written when a text representation
of a timestamp is requested.
|
static java.lang.Integer |
UNKNOWN_OFFSET
Unknown local offset from UTC.
|
static java.lang.Integer |
UTC_OFFSET
Local offset of zero hours from UTC.
|
Constructor and Description |
---|
Timestamp(java.math.BigDecimal millis,
java.lang.Integer localOffset)
Deprecated.
Use
forMillis(BigDecimal, Integer) instead. |
Timestamp(java.util.Calendar cal)
Deprecated.
Use
forCalendar(Calendar) instead. |
Timestamp(int zyear,
int zmonth,
int zday)
Deprecated.
Use
forDay(int, int, int) instead. |
Timestamp(int year,
int month,
int day,
int hour,
int minute,
int second,
java.math.BigDecimal frac,
java.lang.Integer offset)
Deprecated.
|
Timestamp(int year,
int month,
int day,
int hour,
int minute,
java.lang.Integer offset)
Deprecated.
Use
forMinute(int, int, int, int, int, Integer) instead. |
Timestamp(int year,
int month,
int day,
int hour,
int minute,
int second,
java.lang.Integer offset)
Deprecated.
Use
forSecond(int, int, int, int, int, int, Integer) instead. |
Timestamp(long millis,
java.lang.Integer localOffset)
Deprecated.
Use
forMillis(long, Integer) instead. |
Modifier and Type | Method and Description |
---|---|
Timestamp |
addDay(int amount)
Returns a timestamp relative to this one by the given number of days.
|
Timestamp |
addHour(int amount)
Returns a timestamp relative to this one by the given number of hours.
|
Timestamp |
addMillis(long amount)
Returns a timestamp relative to this one by the given number of
milliseconds.
|
Timestamp |
addMinute(int amount)
Returns a timestamp relative to this one by the given number of minutes.
|
Timestamp |
addMonth(int amount)
Returns a timestamp relative to this one by the given number of months.
|
Timestamp |
addSecond(int amount)
Returns a timestamp relative to this one by the given number of seconds.
|
Timestamp |
addYear(int amount)
Returns a timestamp relative to this one by the given number of years.
|
Timestamp |
adjustDay(int amount)
Returns a timestamp relative to this one by the given number of days.
|
Timestamp |
adjustHour(int amount)
Returns a timestamp relative to this one by the given number of hours.
|
Timestamp |
adjustMillis(long amount)
Returns a timestamp relative to this one by the given number of
milliseconds.
|
Timestamp |
adjustMinute(int amount)
Returns a timestamp relative to this one by the given number of minutes.
|
Timestamp |
adjustMonth(int amount)
Returns a timestamp relative to this one by the given number of months.
|
Timestamp |
adjustSecond(int amount)
Returns a timestamp relative to this one by the given number of seconds.
|
Timestamp |
adjustYear(int amount)
Returns a timestamp relative to this one by the given number of years.
|
java.util.Calendar |
calendarValue()
Converts the value of this Timestamp as a
Calendar , in its
local time. |
Timestamp |
clone()
Creates a copy of this Timestamp.
|
int |
compareTo(Timestamp t)
Performs a comparison of the two points in time represented by two
Timestamps.
|
static Timestamp |
createFromUtcFields(Timestamp.Precision p,
int zyear,
int zmonth,
int zday,
int zhour,
int zminute,
int zsecond,
java.math.BigDecimal frac,
java.lang.Integer offset)
Deprecated.
|
java.util.Date |
dateValue()
Converts the value of this Timestamp into a
Date ,
representing the time in UTC. |
boolean |
equals(java.lang.Object t)
Compares this
Timestamp to the specified Object. |
boolean |
equals(Timestamp t)
|
static Timestamp |
forCalendar(java.util.Calendar calendar)
Converts a
Calendar to a Timestamp, preserving the calendar's
time zone as the equivalent local offset when it has at least minutes
precision. |
static Timestamp |
forDateZ(java.util.Date date)
Converts a
Date to a Timestamp in UTC representing the same
point in time. |
static Timestamp |
forDay(int yearZ,
int monthZ,
int dayZ)
Returns a Timestamp, precise to the day, with unknown local offset.
|
static Timestamp |
forEpochSecond(long seconds,
int nanoOffset,
java.lang.Integer localOffset)
Returns a Timestamp that represents the point in time that is
seconds from the unix epoch
(1970-01-01T00:00:00.000Z), with the nanoOffset applied and a given local offset. |
static Timestamp |
forMillis(java.math.BigDecimal millis,
java.lang.Integer localOffset)
The same as
forMillis(long, Integer) but the millisecond component is specified using a
BigDecimal and therefore may include fractional milliseconds. |
static Timestamp |
forMillis(long millis,
java.lang.Integer localOffset)
Returns a Timestamp that represents the point in time that is
millis milliseconds from the epoch,
with a given local offset. |
static Timestamp |
forMinute(int year,
int month,
int day,
int hour,
int minute,
java.lang.Integer offset)
Returns a Timestamp, precise to the minute, with a given local
offset.
|
static Timestamp |
forMonth(int yearZ,
int monthZ)
Returns a Timestamp, precise to the month, with unknown local offset.
|
static Timestamp |
forSecond(int year,
int month,
int day,
int hour,
int minute,
java.math.BigDecimal second,
java.lang.Integer offset)
Returns a Timestamp, precise to the second, with a given local offset.
|
static Timestamp |
forSecond(int year,
int month,
int day,
int hour,
int minute,
int second,
java.lang.Integer offset)
Returns a Timestamp, precise to the second, with a given local offset.
|
static Timestamp |
forSqlTimestampZ(java.sql.Timestamp sqlTimestamp)
Converts a
Timestamp to a Timestamp in UTC representing
the same point in time. |
static Timestamp |
forYear(int yearZ)
Returns a Timestamp, precise to the year, with unknown local offset.
|
int |
getDay()
Returns the day (within the month) of this Timestamp, in its local time.
|
java.math.BigDecimal |
getDecimalMillis()
Returns a BigDecimal representing the Timestamp's point in time that is
the number of milliseconds (including any fractional milliseconds)
from the epoch.
|
java.math.BigDecimal |
getDecimalSecond()
Returns the seconds of this Timestamp.
|
java.math.BigDecimal |
getFractionalSecond()
Deprecated.
|
int |
getHour()
Returns the hour of this Timestamp, in its local time.
|
java.lang.Integer |
getLocalOffset()
Returns the offset of this Timestamp, measured in minutes, for the local
timezone in UTC.
|
long |
getMillis()
Returns a number representing the Timestamp's point in time that is
the number of milliseconds (ignoring any fractional milliseconds)
from the epoch.
|
int |
getMinute()
Returns the minute of this Timestamp, in its local time.
|
int |
getMonth()
Returns the month of this Timestamp, in its local time.
|
Timestamp.Precision |
getPrecision()
Returns the precision of this Timestamp.
|
int |
getSecond()
Returns the seconds of this Timestamp, truncated to an integer.
|
int |
getYear()
Returns the year of this Timestamp, in its local time.
|
int |
getZDay()
Returns the day of this Timestamp, in UTC.
|
java.math.BigDecimal |
getZDecimalSecond()
Returns the seconds of this Timestamp.
|
java.math.BigDecimal |
getZFractionalSecond()
Deprecated.
Use
getZDecimalSecond() instead. |
int |
getZHour()
Returns the hour of this Timestamp, in UTC.
|
int |
getZMinute()
Returns the minute of this Timestamp, in UTC.
|
int |
getZMonth()
Returns the month of this Timestamp, in UTC.
|
int |
getZSecond()
Returns the second of this Timestamp.
|
int |
getZYear()
Returns the year of this Timestamp, in UTC.
|
int |
hashCode()
Returns a hash code consistent with
equals(Object) . |
static Timestamp |
now()
Returns a Timestamp representing the current time (based on the JVM
clock), with an unknown local offset.
|
static Timestamp |
nowZ()
Returns a Timestamp in UTC representing the current time (based on the
the JVM clock).
|
void |
print(java.lang.Appendable out)
Prints to an
Appendable the string representation (in Ion format)
of this Timestamp in its local time. |
void |
printZ(java.lang.Appendable out)
Prints to an
Appendable the string representation (in Ion format)
of this Timestamp in UTC. |
java.lang.String |
toString()
Returns the string representation (in Ion format) of this Timestamp in
its local time.
|
java.lang.String |
toZString()
Returns the string representation (in Ion format) of this Timestamp
in UTC.
|
static Timestamp |
valueOf(java.lang.CharSequence ionFormattedTimestamp)
Returns a new Timestamp that represents the point in time, precision
and local offset defined in Ion format by the
CharSequence . |
Timestamp |
withLocalOffset(java.lang.Integer offset)
Returns a timestamp at the same point in time, but with the given local
offset.
|
public static final java.lang.Integer UNKNOWN_OFFSET
public static final java.lang.Integer UTC_OFFSET
public static final int DEFAULT_MAXIMUM_DIGITS_TEXT
IonTextWriterBuilder.withMaximumTimestampPrecisionDigits(int)
.@Deprecated public Timestamp(int zyear, int zmonth, int zday)
forDay(int, int, int)
instead.
This is equivalent to the corresponding Ion value YYYY-MM-DD
.
@Deprecated public Timestamp(int year, int month, int day, int hour, int minute, java.lang.Integer offset)
forMinute(int, int, int, int, int, Integer)
instead.
This is equivalent to the corresponding Ion value
YYYY-MM-DDThh:mm+-oo:oo
, where oo:oo
represents the
hour and minutes of the local offset from UTC.
offset
- the local offset from UTC, measured in minutes;
may be null
to represent an unknown local offset@Deprecated public Timestamp(int year, int month, int day, int hour, int minute, int second, java.lang.Integer offset)
forSecond(int, int, int, int, int, int, Integer)
instead.
This is equivalent to the corresponding Ion value
YYYY-MM-DDThh:mm:ss+-oo:oo
, where oo:oo
represents the
hour and minutes of the local offset from UTC.
offset
- the local offset from UTC, measured in minutes;
may be null
to represent an unknown local offset.@Deprecated public Timestamp(int year, int month, int day, int hour, int minute, int second, java.math.BigDecimal frac, java.lang.Integer offset)
forSecond(int, int, int, int, int, BigDecimal, Integer)
instead.
This is equivalent to the corresponding Ion value
YYYY-MM-DDThh:mm:ss.fff+-oo:oo
, where oo:oo
represents
the hour and minutes of the local offset from UTC, and fff
represents the fractional seconds.
frac
- the fractional seconds; must not be null
; if negative,
its absolute value is usedoffset
- the local offset from UTC, measured in minutes;
may be null
to represent an unknown local offsetjava.lang.NullPointerException
- if frac
is null
@Deprecated public Timestamp(java.util.Calendar cal)
forCalendar(Calendar)
instead.Calendar
, preserving the
Calendar
's precision and local offset from UTC.
The most precise calendar field of cal
will be used to determine
the precision of the resulting Timestamp.
For example, the calendar field will have a Timestamp precision accordingly:
Calendar.YEAR
- year precision, unknown local offsetCalendar.MONTH
- month precision, unknown local offsetCalendar.DAY_OF_MONTH
- day precision, unknown local offsetCalendar.HOUR_OF_DAY
or Calendar.MINUTE
- minute precisionCalendar.SECOND
- second precisionCalendar.MILLISECOND
- fractional second precisionjava.lang.IllegalArgumentException
- if cal
has no appropriate calendar fields set.@Deprecated public Timestamp(java.math.BigDecimal millis, java.lang.Integer localOffset)
forMillis(BigDecimal, Integer)
instead.millis
milliseconds (including any fractional
milliseconds) from the epoch, with a given local offset.
The resulting Timestamp will be precise to the second if millis
doesn't contain information that is more granular than seconds.
For example, a BigDecimal
of
value 132541995e4 (132541995 × 104)
will return a Timestamp of 2012-01-01T12:12:30Z
,
precise to the second.
The resulting Timestamp will be precise to the fractional second if
millis
contains information that is at least granular to
milliseconds.
For example, a BigDecimal
of
value 1325419950555
will return a Timestamp of 2012-01-01T12:12:30.555Z
,
precise to the fractional second.
millis
- number of milliseconds (including any fractional
milliseconds) from the epoch (1970-01-01T00:00:00.000Z);
must not be null
localOffset
- the local offset from UTC, measured in minutes;
may be null
to represent an unknown local offsetjava.lang.NullPointerException
- if millis
is null
@Deprecated public Timestamp(long millis, java.lang.Integer localOffset)
forMillis(long, Integer)
instead.millis
milliseconds from the epoch, with a given local offset.
The resulting Timestamp will be precise to the fractional second.
millis
- number of milliseconds from the epoch (1970-01-01T00:00:00.000Z)localOffset
- the local offset from UTC, measured in minutes;
may be null
to represent an unknown local offset.@Deprecated public static Timestamp createFromUtcFields(Timestamp.Precision p, int zyear, int zmonth, int zday, int zhour, int zminute, int zsecond, java.math.BigDecimal frac, java.lang.Integer offset)
offset
) already
applied to the time components.
As such, if the given offset
is non-null or zero, the resulting
Timestamp will have time values that DO NOT match the time
parameters. This method also has a behavior of precision "narrowing",
detailed in the sub-section below.
For example, the following method calls will return Timestamps with values (in its local time) respectively:
createFromUtcFields(Precision.SECOND, 2012, 2, 3, 4, 5, 6, 0.007, null) will return 2012-02-03T04:05:06.007-00:00 (match) createFromUtcFields(Precision.SECOND, 2012, 2, 3, 4, 5, 6, 0.007, 0) will return 2012-02-03T04:05:06.007+00:00 (match) createFromUtcFields(Precision.SECOND, 2012, 2, 3, 4, 5, 6, 0.007, 480) will return 2012-02-03T12:05:06.007+08:00 (do not match) createFromUtcFields(Precision.SECOND, 2012, 2, 3, 4, 5, 6, 0.007, -480) will return 2012-02-02T20:05:06.007-08:00 (do not match) createFromUtcFields(Precision.SECOND, 2012, 2, 3, 4, 5, 6, 0.007, 720) will return 2012-02-03T16:05:06.007+12:00 (do not match) createFromUtcFields(Precision.SECOND, 2012, 2, 3, 4, 5, 6, 0.007, -720) will return 2012-02-02T16:05:06.007-12:00 (do not match)Note: All of these resulting Timestamps have the similar value (in UTC) 2012-02-03T04:05:06.007Z.
Any time component that is more precise
than the precision parameter p
will be excluded from the
calculation of the resulting Timestamp's point in time.
For example, the following method calls will return Timestamps with values respectively:
createFromUtcFields(Precision.YEAR , 2012, 2, 3, 4, 5, 6, 0.007, 0) will return 2012T createFromUtcFields(Precision.MONTH , 2012, 2, 3, 4, 5, 6, 0.007, 0) will return 2012-02T createFromUtcFields(Precision.DAY , 2012, 2, 3, 4, 5, 6, 0.007, 0) will return 2012-02-03T createFromUtcFields(Precision.MINUTE , 2012, 2, 3, 4, 5, 6, 0.007, 0) will return 2012-02-03T04:05Z createFromUtcFields(Precision.SECOND , 2012, 2, 3, 4, 5, 6, null, 0) will return 2012-02-03T04:05:06Z createFromUtcFields(Precision.SECOND , 2012, 2, 3, 4, 5, 6, 0.007, 0) will return 2012-02-03T04:05:06.007Z
p
- the desired timestamp precision. The result may have a
different precision if the input data isn't precise enough.offset
- the local offset from UTC, measured in minutes;
may be null
to represent an unknown local offset.public static Timestamp valueOf(java.lang.CharSequence ionFormattedTimestamp)
CharSequence
.ionFormattedTimestamp
- a sequence of characters that is the Ion representation of a
Timestampnull
if the CharSequence
is "null.timestamp"java.lang.IllegalArgumentException
- if the CharSequence
is an invalid Ion representation
of a Timestamp;
or if the CharSequence
has excess characters which
are not one of the following valid thirteen numeric-stop
characters (escaped accordingly for readability):
{}[](),\"\'\ \t\n\r}
public Timestamp clone()
clone
in class java.lang.Object
public static Timestamp forYear(int yearZ)
This is equivalent to the corresponding Ion value YYYYT
.
public static Timestamp forMonth(int yearZ, int monthZ)
This is equivalent to the corresponding Ion value YYYY-MMT
.
public static Timestamp forDay(int yearZ, int monthZ, int dayZ)
This is equivalent to the corresponding Ion value YYYY-MM-DD
.
public static Timestamp forMinute(int year, int month, int day, int hour, int minute, java.lang.Integer offset)
This is equivalent to the corresponding Ion value
YYYY-MM-DDThh:mm+-oo:oo
, where oo:oo
represents the
hour and minutes of the local offset from UTC.
The values of the year
, month
, day
,
hour
, and minute
parameters are relative to the
local offset
.
offset
- the local offset from UTC, measured in minutes;
may be null
to represent an unknown local offsetpublic static Timestamp forSecond(int year, int month, int day, int hour, int minute, int second, java.lang.Integer offset)
This is equivalent to the corresponding Ion value
YYYY-MM-DDThh:mm:ss+-oo:oo
, where oo:oo
represents the
hour and minutes of the local offset from UTC.
The values of the year
, month
, day
,
hour
, minute
and second
parameters are relative
to the local offset
.
offset
- the local offset from UTC, measured in minutes;
may be null
to represent an unknown local offsetpublic static Timestamp forSecond(int year, int month, int day, int hour, int minute, java.math.BigDecimal second, java.lang.Integer offset)
This is equivalent to the corresponding Ion value
YYYY-MM-DDThh:mm:ss.sss+-oo:oo
, where oo:oo
represents
the hour and minutes of the local offset from UTC.
The values of the year
, month
, day
,
hour
, minute
and second
parameters are relative
to the local offset
.
second
- must be at least zero and less than 60. Must not be null.offset
- the local offset from UTC, measured in minutes;
may be null
to represent an unknown local offsetpublic static Timestamp forMillis(long millis, java.lang.Integer localOffset)
millis
milliseconds from the epoch,
with a given local offset.
The resulting Timestamp will be precise to the millisecond.
millis
is relative to UTC, regardless of the value supplied for localOffset
. This
varies from the forMinute(int, int, int, int, int, java.lang.Integer)
and forSecond(int, int, int, int, int, int, java.lang.Integer)
methods that assume the specified date and time
values are relative to the local offset. For example, the following two Timestamps represent
the same point in time:
Timestamp theEpoch = Timestamp.forMillis(0, 0);
Timestamp alsoTheEpoch = Timestamp.forSecond(1969, 12, 31, 23, 0, BigDecimal.ZERO, -60);
millis
- the number of milliseconds from the epoch (1970-01-01T00:00:00.000Z) in UTC.localOffset
- the local offset from UTC, measured in minutes;
may be null
to represent an unknown local offset.public static Timestamp forMillis(java.math.BigDecimal millis, java.lang.Integer localOffset)
forMillis(long, Integer)
but the millisecond component is specified using a
BigDecimal
and therefore may include fractional milliseconds.millis
- number of milliseconds (including any fractional
milliseconds) from the epoch (1970-01-01T00:00:00.000Z);
must not be null
localOffset
- the local offset from UTC, measured in minutes;
may be null
to represent an unknown local offsetjava.lang.NullPointerException
- if millis
is null
public static Timestamp forEpochSecond(long seconds, int nanoOffset, java.lang.Integer localOffset)
seconds
from the unix epoch
(1970-01-01T00:00:00.000Z), with the nanoOffset
applied and a given local offset.
This function is intended to allow easy conversion to Timestamp from Java 8's java.time.Instant
without having to port this library to Java 8. The following snippet will yield a Timestamp ts
that equivalent to the java.time.Instant
i
:
Instant i = Instant.now();
Timestamp ts = Timestamp.forEpochSecond(i.getEpochSecond(), i.getNano(), 0);
Like forMillis(long, java.lang.Integer)
, seconds
is relative to UTC, regardless of the value
supplied for localOffset
.
seconds
- The number of seconds from the unix epoch (1970-01-01T00:00:00.000Z) UTC.nanoOffset
- The number of nanoseconds for the fractional component. Must be between 0 and 999,999,999.localOffset
- the local offset from UTC, measured in minutes;
may be null
to represent an unknown local offset.public static Timestamp forCalendar(java.util.Calendar calendar)
Calendar
to a Timestamp, preserving the calendar's
time zone as the equivalent local offset when it has at least minutes
precision.Calendar
;
or null
if calendar
is null
public static Timestamp forDateZ(java.util.Date date)
Date
to a Timestamp in UTC representing the same
point in time.
The resulting Timestamp will be precise to the millisecond.
null
if date
is null
public static Timestamp forSqlTimestampZ(java.sql.Timestamp sqlTimestamp)
Timestamp
to a Timestamp in UTC representing
the same point in time.
The resulting Timestamp will be precise to the nanosecond.
sqlTimestamp
- assumed to have nanoseconds precisionnull
if sqlTimestamp
is null
public static Timestamp now()
The resulting Timestamp will be precise to the millisecond.
public static Timestamp nowZ()
The resulting Timestamp will be precise to the millisecond.
public java.util.Date dateValue()
Date
,
representing the time in UTC.
This method will return the same result for all Timestamps representing the same point in time, regardless of the local offset.
Because Date
instances are mutable, this method returns a
new instance from each call.
Date
instance, in UTCpublic java.util.Calendar calendarValue()
Calendar
, in its
local time.
Because Calendar
instances are mutable, this method returns a
new instance from each call.
Calendar
instance, in its local time.public long getMillis()
This method will return the same result for all Timestamps representing the same point in time, regardless of the local offset.
public java.math.BigDecimal getDecimalMillis()
This method will return the same result for all Timestamps representing the same point in time, regardless of the local offset.
public Timestamp.Precision getPrecision()
public java.lang.Integer getLocalOffset()
For example, calling this method on Timestamps of:
1969-02-23T07:00+07:00
will return 420
1969-02-22T22:45:00.00-01:15
will return -75
1969-02-23
(by Ion's definition, equivalent to
1969-02-23T00:00-00:00
) will return null
null
if the local offset is unknown
(i.e. -00:00
)public int getYear()
public int getMonth()
public int getDay()
public int getHour()
public int getMinute()
public int getSecond()
Seconds are not affected by local offsets.
As such, this method produces the same output as getZSecond()
.
getZSecond()
public java.math.BigDecimal getDecimalSecond()
Seconds are not affected by local offsets.
As such, this method produces the same output as
getZDecimalSecond()
.
getZDecimalSecond()
@Deprecated public java.math.BigDecimal getFractionalSecond()
Fractional seconds are not affected by local offsets.
As such, this method produces the same output as
getZFractionalSecond()
.
null
is returned if the Timestamp isn't
precise to the fractional secondUse {@link #getDecimalSecond()} instead.
public int getZYear()
public int getZMonth()
public int getZDay()
public int getZHour()
public int getZMinute()
public int getZSecond()
Seconds are not affected by local offsets.
As such, this method produces the same output as getSecond()
.
getSecond()
public java.math.BigDecimal getZDecimalSecond()
Seconds are not affected by local offsets.
As such, this method produces the same output as
getDecimalSecond()
.
getDecimalSecond()
@Deprecated public java.math.BigDecimal getZFractionalSecond()
getZDecimalSecond()
instead.
Fractional seconds are not affected by local offsets.
As such, this method produces the same output as
getFractionalSecond()
.
null
is returned if the Timestamp isn't
precise to the fractional secondgetFractionalSecond()
public Timestamp withLocalOffset(java.lang.Integer offset)
public java.lang.String toString()
toString
in class java.lang.Object
IonException
- if the text representation of the timestamp requires more than
DEFAULT_MAXIMUM_DIGITS_TEXT
.toZString()
,
print(Appendable)
public java.lang.String toZString()
IonException
- if the text representation of the timestamp requires more than
DEFAULT_MAXIMUM_DIGITS_TEXT
.toString()
,
printZ(Appendable)
public void print(java.lang.Appendable out) throws java.io.IOException
Appendable
the string representation (in Ion format)
of this Timestamp in its local time.
This method produces the same output as toString()
.
out
- not null
java.io.IOException
- propagated when the Appendable
throws itIonException
- if the text representation of the timestamp requires more than
DEFAULT_MAXIMUM_DIGITS_TEXT
.printZ(Appendable)
public void printZ(java.lang.Appendable out) throws java.io.IOException
Appendable
the string representation (in Ion format)
of this Timestamp in UTC.
This method produces the same output as toZString()
.
out
- not null
java.io.IOException
- propagated when the Appendable
throws it.IonException
- if the text representation of the timestamp requires more than
DEFAULT_MAXIMUM_DIGITS_TEXT
.print(Appendable)
public final Timestamp adjustMillis(long amount)
This method always returns a Timestamp with the same precision as
the original. After performing the arithmetic, the resulting Timestamp's
seconds value will be truncated to the same fractional precision as the
original. For example, adjusting 2012-04-01T00:00:00Z
by one
millisecond results in 2012-04-01T00:00:00Z
; adjusting
2012-04-01T00:00:00.0010Z
by -1 millisecond results in
2012-04-01T00:00:00.0000Z
. To extend the precision when the
original Timestamp has coarser than SECOND precision and to avoid
truncation of the seconds value, use addSecond(int)
.
amount
- a number of milliseconds.public final Timestamp addMillis(long amount)
This method always returns a Timestamp with SECOND precision and a seconds
value precise at least to the millisecond. For example, adding one millisecond
to 2011T
results in 2011-01-01T00:00:00.001-00:00
. To receive
a Timestamp that always maintains the same precision as the original, use
adjustMillis(long)
.
milliseconds.
amount
- a number of milliseconds.public final Timestamp adjustSecond(int amount)
This method always returns a Timestamp with the same precision as
the original. For example, adjusting 2012-04-01T00:00Z
by one
second results in 2012-04-01T00:00Z
; adjusting
2012-04-01T00:00:00Z
by -1 second results in
2012-03-31T23:59:59Z
. To extend the precision when the original
Timestamp has coarser than SECOND precision, use addSecond(int)
.
amount
- a number of seconds.public final Timestamp addSecond(int amount)
This method always returns a Timestamp with SECOND precision.
For example, adding one second to 2011T
results in
2011-01-01T00:00:01-00:00
. To receive a Timestamp that always
maintains the same precision as the original, use adjustSecond(int)
.
amount
- a number of seconds.public final Timestamp adjustMinute(int amount)
This method always returns a Timestamp with the same precision as
the original. For example, adjusting 2012-04-01T
by one minute
results in 2012-04-01T
; adjusting 2012-04-01T00:00-00:00
by -1 minute results in 2012-03-31T23:59-00:00
. To extend the
precision when the original Timestamp has coarser than MINUTE precision,
use addMinute(int)
.
amount
- a number of minutes.public final Timestamp addMinute(int amount)
This method always returns a Timestamp with at least MINUTE precision.
For example, adding one minute to 2011T
results in
2011-01-01T00:01-00:00
. To receive a Timestamp that always
maintains the same precision as the original, use adjustMinute(int)
.
amount
- a number of minutes.public final Timestamp adjustHour(int amount)
This method always returns a Timestamp with the same precision as
the original. For example, adjusting 2012-04-01T
by one hour
results in 2012-04-01T
; adjusting 2012-04-01T00:00-00:00
by -1 hour results in 2012-03-31T23:00-00:00
. To extend the
precision when the original Timestamp has coarser than MINUTE precision,
use addHour(int)
.
amount
- a number of hours.public final Timestamp addHour(int amount)
This method always returns a Timestamp with at least MINUTE precision.
For example, adding one hour to 2011T
results in
2011-01-01T01:00-00:00
. To receive a Timestamp that always
maintains the same precision as the original, use adjustHour(int)
.
amount
- a number of hours.public final Timestamp adjustDay(int amount)
This method always returns a Timestamp with the same precision as
the original. For example, adjusting 2012-04T
by one day results
in 2012-04T
; adjusting 2012-04-01T
by -1 days results in
2012-03-31T
. To extend the precision when the original Timestamp
has coarser than DAY precision, use addDay(int)
.
amount
- a number of days.public final Timestamp addDay(int amount)
amount
- a number of days.public final Timestamp adjustMonth(int amount)
This method always returns a Timestamp with the same precision as the
original. For example, adjusting 2011T
by one month results in
2011T
; adding 12 months to 2011T
results in 2012T
.
To extend the precision when the original Timestamp has coarser than MONTH
precision, use addMonth(int)
.
amount
- a number of months.public final Timestamp addMonth(int amount)
2011-01-31
results in 2011-02-28
.amount
- a number of months.public final Timestamp adjustYear(int amount)
2012-02-29
by one year results in 2013-02-28
.
Because YEAR is the coarsest precision possible, this method always
returns a Timestamp with the same precision as the original and
behaves identically to addYear(int)
.
amount
- a number of years.public final Timestamp addYear(int amount)
2012-02-29
results in 2013-02-28
.amount
- a number of years.public int hashCode()
equals(Object)
.
hashCode
in class java.lang.Object
public int compareTo(Timestamp t)
t
, then -1
is returned.
If t
precedes this Timestamp then 1
is returned.
If the Timestamps represent the same point in time, then
0
is returned.
Note that a 0
result does not imply that the two Timestamps are
equals(java.lang.Object)
, as the local offset or precision of the two Timestamps
may be different.
This method is provided in preference to individual methods for each of
the six boolean comparison operators (<, ==, >, >=, !=, <=).
The suggested idiom for performing these comparisons is:
(x.compareTo(y)
<op>0)
,
where <op> is one of the six comparison operators.
For example, the pairs below will return a 0
result:
2009T
2009-01T
2009-01-01T
2009-01-01T00:00Z
2009-01-01T00:00:00Z
2009-01-01T00:00:00.0Z
2009-01-01T00:00:00.00Z
2008-12-31T16:00-08:00
2008-12-31T12:00-12:00
2009-01-01T12:00+12:00
Use the equals(Timestamp)
method to compare the point
in time, including precision and local offset.
compareTo
in interface java.lang.Comparable<Timestamp>
t
- the other Timestamp
to compare this Timestamp
toTimestamp
is less than, equal to, or greater than t
respectivelyjava.lang.NullPointerException
- if t
is null.equals(Timestamp)
public boolean equals(java.lang.Object t)
Timestamp
to the specified Object.
The result is true
if and only if the parameter is a
Timestamp
object that represents the same point in time,
precision and local offset as this Timestamp.
Use the compareTo(Timestamp)
method to compare only the point
in time, ignoring precision and local offset.
equals
in class java.lang.Object
equals(Timestamp)
,
compareTo(Timestamp)
public boolean equals(Timestamp t)
Timestamp
to another Timestamp
object.
The result is true
if and only if the parameter
represents the same point in time and has
the same precision and local offset as this object.
These pairs are equals(java.lang.Object)
to each other, as they
represent the same points in time, precision and local offset:
2001-01-01T11:22+00:00
(minute precision, in UTC)2001-01-01T11:22Z
(minute precision, in UTC)
On the other hand, none of these pairs are equals(java.lang.Object)
to each other,
they represent the same points in time, but with different precisions
and/or local offsets:
2001T
(year precision, unknown local offset)2001-01T
(month precision, unknown local offset)2001-01-01T
(day precision, unknown local offset)2001-01-01T00:00-00:00
(second precision, unknown local offset)2001-01-01T00:00+00:00
(second precision, in UTC)2001-01-01T00:00.000-00:00
(millisecond precision, unknown local offset)2001-01-01T00:00.000+00:00
(millisecond precision, in UTC)
Use the compareTo(Timestamp)
method to compare only the point
in time, ignoring precision and local offset.
compareTo(Timestamp)