Comparable<TimePoint>
public class TimePoint extends Object implements Comparable<TimePoint>
Time points are immutable objects that can be compared or converted to and from standard Java time objects like Calendar, Date or time in milliseconds since 1 January 1970 (i.e. Epoch time).
New time points can be calculated relative to this time point, using the methods forward, back, next, floor, ceil and round.
ISO 8601 representations of date and time can be obtained by calling the date, weekDate, ordinalDate, time or dateTime methods supplying a local time zone and a locale (for week dates).
Convenience methods for creating time points for the current time and for the beginning of the today are also included.
Modifier and Type | Field | Description |
---|---|---|
static Locale |
ISO8601 |
|
static TimeZone |
LOCAL |
|
static TimeZone |
UTC |
Modifier and Type | Method | Description |
---|---|---|
TimePoint |
back(int amount,
Unit unit,
TimeZone tz) |
Equivalent to calling back(Duration.create(amount, unit), tz).
|
TimePoint |
back(Duration duration,
TimeZone tz) |
Returns a new time point moved back the length of a duration.
|
TimePoint |
ceil(Unit precision,
TimeZone tz,
Locale locale) |
Round this time point up to the closest whole unit.
|
int |
compareTo(TimePoint that) |
|
CalendarDate |
date(TimeZone tz) |
Returns the calendar date (YYYY-MM-DD) representing the day of
this time point, observing local time zone.
|
IsoDateTime |
dateTime(TimeZone tz) |
Returns the date and time (YYYY-MM-DDTHH:MM:SS) for this time point,
observing local time zone.
|
static TimePoint |
endOfToday(TimeZone tz) |
|
boolean |
equals(Object o) |
|
TimePoint |
floor(Unit precision,
TimeZone tz,
Locale locale) |
Round this time point down to the closest whole unit.
|
TimePoint |
forward(int amount,
Unit unit,
TimeZone tz) |
Equivalent to calling forward(Duration.create(amount, unit), tz).
|
TimePoint |
forward(Duration duration,
TimeZone tz) |
Returns a new time point moved forward the length of a duration.
|
static TimePoint |
fromCalendar(Calendar calendar) |
|
static TimePoint |
fromDate(Date date) |
|
static TimePoint |
fromMillis(long millis) |
|
int |
hashCode() |
|
TimePoint |
next(int amount,
Unit unit,
TimeZone tz,
Locale locale) |
Equivalent to calling next(Duration.create(amount, unit), tz, locale).
|
TimePoint |
next(Duration duration,
TimeZone tz,
Locale locale) |
Returns a new time point representing the start of the next period as defined by a duration.
|
static TimePoint |
now() |
|
OrdinalDate |
ordinalDate(TimeZone tz) |
Returns the ordinal date (YYYY-DDD) representing the day of
this time point, observing local time zone.
|
static TimePoint |
parse(String iso,
TimeZone tz) |
Parses a date-time specification as defined by ISO 8601 and
returns a time point valid for the specified date-time.
|
TimePoint |
round(Unit precision,
TimeZone tz,
Locale locale) |
Round this time point to the closest whole unit.
|
Time |
time(TimeZone tz) |
Returns the time of day (HH:MM:SS) for this time point,
observing local time zone.
|
GregorianCalendar |
toCalendar(TimeZone tz) |
Converts this time point to a Gregorian calendar with the specified
time zone and the default locale.
|
GregorianCalendar |
toCalendar(TimeZone tz,
Locale locale) |
Converts this time point to a Gregorian calendar with the specified
time zone and locale.
|
Date |
toDate() |
Converts this time point to a java.util.Date object.
|
static TimePoint |
today(TimeZone tz) |
|
long |
toMillis() |
Converts this time point to Epoch time, i.e.
|
String |
toString() |
Returns a string on the format YYYY-MM-DDTHH:MM:SSZ representing this
time point.
|
String |
toString(boolean formal) |
If formal, returns a string on the format YYYY-MM-DDTHH:MM:SSZ representing this
time point.
|
WeekDate |
weekDate(TimeZone tz) |
Returns the week date (YYYY-Www-D) representing the day of
this time point, observing local time zone and local week rules.
|
public static final TimeZone UTC
public static final TimeZone LOCAL
public static final Locale ISO8601
public static TimePoint now()
public static TimePoint today(TimeZone tz)
tz
- The local time zone.public static TimePoint endOfToday(TimeZone tz)
tz
- The local time zone.public static TimePoint fromMillis(long millis)
millis
- epoch timepublic static TimePoint fromDate(Date date)
date
- Date objectpublic static TimePoint fromCalendar(Calendar calendar)
calendar
- Calendar objectpublic static TimePoint parse(String iso, TimeZone tz)
iso
- The input string.tz
- The local time zone.public TimePoint next(int amount, Unit unit, TimeZone tz, Locale locale)
amount
- The amount of units.unit
- Unit of time.tz
- The locale time zone.locale
- The locale.public TimePoint next(Duration duration, TimeZone tz, Locale locale)
If this time point is at the start of a period, then the new time point is moved forward by the length of the duration. Otherwise, the new time point is the ceiling of this time point, with the precision of the duration used as unit.
duration
- The duration of a period.tz
- The local time zone.locale
- The locale.public TimePoint forward(int amount, Unit unit, TimeZone tz)
amount
- The amount of units.unit
- Unit of time.tz
- The locale time zone.public TimePoint forward(Duration duration, TimeZone tz)
duration
- The duration to move forward.tz
- The local time zone.public TimePoint back(int amount, Unit unit, TimeZone tz)
amount
- The amount of units.unit
- Unit of time.tz
- The locale time zone.public TimePoint back(Duration duration, TimeZone tz)
duration
- The duration to move back.tz
- The local time zone.public TimePoint floor(Unit precision, TimeZone tz, Locale locale)
precision
- The unit to round to.tz
- The local time zone.locale
- The locale.public TimePoint ceil(Unit precision, TimeZone tz, Locale locale)
precision
- The unit to round to.tz
- The local time zone.locale
- The locale.public TimePoint round(Unit precision, TimeZone tz, Locale locale)
precision
- The unit to round to.tz
- The local time zone.locale
- The locale.public CalendarDate date(TimeZone tz)
tz
- The local time zone.public WeekDate weekDate(TimeZone tz)
tz
- The local time zone.public OrdinalDate ordinalDate(TimeZone tz)
tz
- The local time zone.public Time time(TimeZone tz)
tz
- The local time zone.public IsoDateTime dateTime(TimeZone tz)
tz
- The local time zone.public GregorianCalendar toCalendar(TimeZone tz)
tz
- The time zone.public GregorianCalendar toCalendar(TimeZone tz, Locale locale)
tz
- The time zone.locale
- The locale.public Date toDate()
public long toMillis()
public int compareTo(TimePoint that)
compareTo
in interface Comparable<TimePoint>
public String toString()
public String toString(boolean formal)
formal
- formal representation of time point.Copyright © 2021 Apptus Technologies AB. All rights reserved.