|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface Time
A complete time with date and time of day, and a lot of utilities.
The time is relative to the local timezone, and contains no timezone information. It is simply a "local time".
The framework is aware of leap years, but not of leap seconds nor daylight saving time corrections.
The timestamp contains year, month, day, hour, minute, second and millisecond information, and the valid range of times is from Jan 1, 1000, 00:00:00.000 to Dec 31, 9999, 23:59:59.999 (inclusive).
Time objects are always immutable - they cannot be changed once created.
The natural order of this class orders instances in chronological order, and two instances are considered equal if and only if they coincide on all parameters down to milliseconds.
Example usage
Create new instances: |
Time.factory.now() Time.factory.getDefault() Time.factory.parse(...)
|
Formatting: |
Time.iso().formatXXX() Time.eur().formatXXX() Time.us().formatXXX()
|
Serializing: |
Time.serialize() Time.factory.deserialize()
|
Field Summary | |
---|---|
static TimeFactory |
factory
A default implementation of a TimeFactory , for creating new
instances. |
Method Summary | |
---|---|
int |
day()
|
boolean |
equals(Object other)
|
TimeFormatter |
eur()
Provides a formatter for this time instance that formats timestamps according to some de-facto European standard. |
DayDate |
getDate()
|
DayOfWeek |
getDayOfWeek()
Calculates the day of week of this time. |
TimeOfDay |
getTimeOfDay()
|
int |
hashCode()
|
int |
hour()
|
boolean |
isAfter(int hours,
int minutes)
Determines if this is after (inclusive) the given time of day. |
boolean |
isAfter(int hours,
int minutes,
int seconds)
Determines if this is after (inclusive) the given time of day. |
boolean |
isAfter(Time time)
Determines if this is after (inclusive) the given time. |
boolean |
isAfter(TimeOfDay timeOfDay)
Determines if this is after (inclusive) the given time of day. |
boolean |
isBefore(int hours,
int minutes)
Determines if this is before (exclusive) the given time of day. |
boolean |
isBefore(int hours,
int minutes,
int seconds)
Determines if this is before (exclusive) the given time of day. |
boolean |
isBefore(Time time)
Determines if this is before (exclusive) the given time. |
boolean |
isBefore(TimeOfDay timeOfDay)
Determines if this is before (exclusive) the given time of day. |
boolean |
isLaterDayThan(Time time)
Determines whether this is in a later day than the given time. |
boolean |
isLaterHourThan(Time time)
Determines whether this is in a later hour than the given time. |
boolean |
isLaterMinuteThan(Time time)
Determines whether this is in a later minute than the given time. |
boolean |
isLaterMonthThan(Time time)
Determines whether this is in a later month than the given time. |
boolean |
isLaterSecondThan(Time time)
Determines whether this is in a later second than the given time. |
boolean |
isLaterYearThan(Time time)
Determines whether this is in a later year than the given time. |
TimeFormatter |
iso()
Provides a formatter for this time instance that formats timestamps according to the ISO-8601 standard. |
boolean |
isSameDayAs(Time time)
Determines whether this is in the same day (of the same year) as the given time. |
boolean |
isSameHourAs(Time time)
Determines whether this is in the same hour (of the same day and year) as the given time. |
boolean |
isSameMinuteAs(Time time)
Determines whether this is in the same minute (of the same hour, day and year) as the given time. |
boolean |
isSameMonthAs(Time time)
Determines whether this is in the same month and the same year as the given time. |
boolean |
isSameSecondAs(Time time)
Determines whether this is in the same second (of the same minute, hour, day and year) as the given time. |
boolean |
isSameYearAs(Time time)
Determines whether this is in the same year as the given time. |
int |
millis()
|
int |
minute()
|
Month |
month()
|
long |
pack()
Creates a long representation of the timestamp that is packed into the first 49 bits of the long, and still represents the timestamp uniquely. |
Time |
plusDays(int offset)
Adds or subtracts the given number of days to this time. |
Time |
plusHours(int offset)
Adds or subtracts the given number of hours to this time. |
Time |
plusMillis(long offset)
Adds or subtracts the given number of milliseconds to this time. |
Time |
plusMinutes(long offset)
Adds or subtracts the given number of minutes to this time. |
Time |
plusMonths(int offset)
Adds or subtracts the given number of months to this time. |
Time |
plusSeconds(long offset)
Adds or subtracts the given number of seconds to this time. |
Time |
plusYears(int offset)
Adds or subtracts the given number of years to this time. |
int |
second()
|
String |
serialize()
|
Date |
toJavaUtilDate()
Converts this time to a Date in the default timezone. |
Date |
toJavaUtilDate(TimeZone timeZone)
Converts this time to a Date in the given timezone. |
long |
toLong()
Creates an long representation of the timestamp, which when written in base 10 is the string YYYYMMDDhhmmssnnn , where
nnn is the milliseconds. |
String |
toString()
Overrides Object.toString() . |
TimeFormatter |
us()
Provides a formatter for this time instance that formats timestamps according to the US standard. |
int |
year()
|
Methods inherited from interface java.lang.Comparable |
---|
compareTo |
Field Detail |
---|
static final TimeFactory factory
TimeFactory
, for creating new
instances. The factory will create serializable
instances.
Method Detail |
---|
DayDate getDate()
date
represented by this time, a full date
with year, month and day of month.TimeOfDay getTimeOfDay()
time of day
represented by this time.int year()
Month month()
month
represented by this time.int day()
int hour()
int minute()
int second()
int millis()
DayOfWeek getDayOfWeek()
Time plusYears(int offset)
offset
- The offset in years. Can be positive, zero or negative.
TimeOutOfRangeException
- If the resulting time is out of range.Time plusMonths(int offset)
If adding the given number of months would make the day of month over the new month's maximum it will be reduced to the proper maximum. Hence, adding three months to 2011-05-31 will give 2011-08-31, but adding four will give 2011-09-30. And adding 13 months to 2010-01-30 will give the date 2011-02-28.
offset
- The offset in months. Can be positive, zero or negative.
TimeOutOfRangeException
- If the resulting time is out of range.Time plusDays(int offset)
offset
- The offset in days. Can be positive, zero or negative.
TimeOutOfRangeException
- If the resulting time is out of range.Time plusHours(int offset)
offset
- The offset in hours. Can be positive, zero or negative.
TimeOutOfRangeException
- If the resulting time is out of range.Time plusMinutes(long offset)
offset
- The offset in minutes. Can be positive, zero or negative.
TimeOutOfRangeException
- If the resulting time is out of range.Time plusSeconds(long offset)
offset
- The offset in seconds. Can be positive, zero or negative.
TimeOutOfRangeException
- If the resulting time is out of range.Time plusMillis(long offset)
offset
- The offset in millis. Can be positive, zero or negative.
TimeOutOfRangeException
- If the resulting time is out of range.boolean isAfter(Time time)
time
- The time to compare to.
boolean isAfter(TimeOfDay timeOfDay)
timeOfDay
- The time of day to compare to.
boolean isAfter(int hours, int minutes)
hours
- The hour part of the time of day to compare to, in the range
0-23.minutes
- The minute part of the time of day to compare to, in the
range 0-59.
boolean isAfter(int hours, int minutes, int seconds)
hours
- The hour part of the time of day to compare to, in the range
0-23.minutes
- The minute part of the time of day to compare to, in the
range 0-59.seconds
- The second part of the time of day to compare to, in the
range 0-59.
boolean isBefore(Time time)
time
- The time to compare to.
boolean isBefore(TimeOfDay timeOfDay)
timeOfDay
- The time of day to compare to.
boolean isBefore(int hours, int minutes)
hours
- The hour part of the time of day to compare to, in the range
0-23.minutes
- The minute part of the time of day to compare to, in the
range 0-59.
boolean isBefore(int hours, int minutes, int seconds)
hours
- The hour part of the time of day to compare to, in the range
0-23.minutes
- The minute part of the time of day to compare to, in the
range 0-59.seconds
- The second part of the time of day to compare to, in the
range 0-59.
boolean isLaterYearThan(Time time)
time
- The time to compare to.
boolean isSameYearAs(Time time)
time
- The time to compare to.
boolean isLaterMonthThan(Time time)
time
- The time to compare to.
boolean isSameMonthAs(Time time)
time
- The time to compare to.
boolean isLaterDayThan(Time time)
time
- The time to compare to.
boolean isSameDayAs(Time time)
time
- The time to compare to.
boolean isLaterHourThan(Time time)
time
- The time to compare to.
boolean isSameHourAs(Time time)
time
- The time to compare to.
boolean isLaterMinuteThan(Time time)
time
- The time to compare to.
boolean isSameMinuteAs(Time time)
time
- The time to compare to.
boolean isLaterSecondThan(Time time)
time
- The time to compare to.
boolean isSameSecondAs(Time time)
time
- The time to compare to.
boolean equals(Object other)
equals
in class Object
int hashCode()
hashCode
in class Object
TimeFormatter iso()
YYYY-MM-DD
and YYYYMMDD
.
TimeFormatter eur()
DD.MM.YYYY
and
DDMMYYYY
.
TimeFormatter us()
MM/DD/YYYY
and MMDDYYYY
.
String serialize()
YYYYMMDDhhmmssnnnn
, where nnn
is the
milliseconds.Date toJavaUtilDate()
Date
in the default timezone.
Date toJavaUtilDate(TimeZone timeZone)
Date
in the given timezone.
timeZone
- The time zone, or null
to use the default
time zone.
String toString()
Object.toString()
.
toString
in class Object
YYYY-MM-DD hh:mm:ss.nnn
,
where nnn
is the milliseconds.long toLong()
YYYYMMDDhhmmssnnn
, where
nnn
is the milliseconds. E.g, the timestamp 2011-03-02
16:42:14.308 is represented as the long 20110302164214308. Note that the
maximum value is 99991231235959999, which is a valid long.
long pack()
This can be used instead of the toLong()
method (which uses the
first 57 bits of the long) whenever data compression is of utmost
importance. If it is not, consider using toLong()
instead.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |