public class TimeString extends Object implements Comparable<TimeString>
Immutable, internally represented as a string (in ISO format), and can support unlimited precision (milliseconds, nanoseconds).
| Modifier and Type | Field and Description |
|---|---|
private static Pattern |
PATTERN |
(package private) String |
v |
| Modifier | Constructor and Description |
|---|---|
|
TimeString(int h,
int m,
int s)
Creates a TimeString for hour, minute, second and millisecond values.
|
|
TimeString(String v)
Creates a TimeString.
|
private |
TimeString(String v,
boolean ignore)
Internal constructor, no validation.
|
| Modifier and Type | Method and Description |
|---|---|
int |
compareTo(TimeString o) |
boolean |
equals(Object o) |
static TimeString |
fromCalendarFields(Calendar calendar)
Creates a TimeString from a Calendar.
|
static TimeString |
fromMillisOfDay(int i) |
private int |
getHour() |
private int |
getMillisInSecond() |
int |
getMillisOfDay() |
private int |
getMinute() |
private int |
getSecond() |
int |
hashCode() |
private static String |
hms(int h,
int m,
int s)
Validates an hour-minute-second value and converts to a string.
|
private int |
precision() |
TimeString |
round(int precision) |
Calendar |
toCalendar() |
String |
toString() |
String |
toString(int precision)
Converts this TimestampString to a string, truncated or padded with
zeroes to a given precision.
|
TimeString |
withFraction(String fraction)
Sets the fraction field of a
TimeString. |
TimeString |
withMillis(int millis)
Sets the fraction field of a
TimeString to a given number
of milliseconds. |
TimeString |
withNanos(int nanos)
Sets the fraction field of a
TimeString to a given number
of nanoseconds. |
private TimeString(String v, boolean ignore)
public TimeString(String v)
public TimeString(int h,
int m,
int s)
private static String hms(int h, int m, int s)
public TimeString withMillis(int millis)
TimeString to a given number
of milliseconds. Nukes the value set via withNanos(int).
For example,
new TimeString(1970, 1, 1, 2, 3, 4).withMillis(56)
yields TIME '1970-01-01 02:03:04.056'.
public TimeString withNanos(int nanos)
TimeString to a given number
of nanoseconds. Nukes the value set via withMillis(int).
For example,
new TimeString(1970, 1, 1, 2, 3, 4).withNanos(56789)
yields TIME '1970-01-01 02:03:04.000056789'.
public TimeString withFraction(String fraction)
TimeString.
The precision is determined by the number of leading zeros.
Trailing zeros are stripped.
For example,
new TimeString(1970, 1, 1, 2, 3, 4).withFraction("00506000")
yields TIME '1970-01-01 02:03:04.00506'.
public int compareTo(@Nonnull TimeString o)
compareTo in interface Comparable<TimeString>public static TimeString fromCalendarFields(Calendar calendar)
public static TimeString fromMillisOfDay(int i)
public TimeString round(int precision)
public int getMillisOfDay()
private int getMillisInSecond()
private int getHour()
private int getMinute()
private int getSecond()
public Calendar toCalendar()
public String toString(int precision)
private int precision()
Copyright © 2012–2018 The Apache Software Foundation. All rights reserved.