|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.xins.common.text.DateConverter
Utility class for converting a UNIX Epoch date to a human-readable time stamp.
For example, the date 26 July 2003, time 17:03, 59 seconds and 653
milliseconds will convert to the string
"2003.07.26 17:03:59.653"
.
See the Wikipedia article about the UNIX Epoch for more information.
Constructor Summary | |
DateConverter(boolean withCentury)
Creates a new DateConverter . |
Method Summary | |
String |
format(long date)
Formats the specified timestamp as a String . |
void |
format(long date,
char[] buffer,
int offset)
Formats the specified timestamp as a string in a character buffer. |
static String |
toDateString(long time)
Convert the specified long to a human-readable time stamp. |
static String |
toDateString(TimeZone timeZone,
long n)
Convert the specified long to a human-readable time stamp. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public DateConverter(boolean withCentury)
DateConverter
.
withCentury
- true
if the century should be in the result,
false
otherwise.Method Detail |
public static String toDateString(long time) throws IllegalArgumentException
long
to a human-readable time stamp.
The current time zone is used.
time
- the time stamp to be converted to a human-readable character string,
as a number of milliseconds since the
UNIX Epoch.
must be greater than Long.MIN_VALUE
and smaller than
Long.MAX_VALUE
.
null
.
IllegalArgumentException
- if n == Long.MIN_VALUE
|| n == Long.MAX_VALUE
.public static String toDateString(TimeZone timeZone, long n) throws IllegalArgumentException
long
to a human-readable time stamp.
timeZone
- the time zone to use, cannot be null
.n
- the time stamp to be converted to a human-readable character string,
as a number of milliseconds since the Epoch (midnight January 1,
1970), must be greater than Long.MIN_VALUE
and smaller than
Long.MAX_VALUE
.
null
.
IllegalArgumentException
- if n == Long.MIN_VALUE
|| n == Long.MAX_VALUE
|| timeZone == null
.public String format(long date) throws IllegalArgumentException
String
. Depending on
the setting of the withCentury property (passed to the
constructor), the format is as follows. If withCentury is set,
then the format is:
CCYYMMDD-hhmmssSSS (length is 18)Otherwise, if withCentury is not set, then the format is without the century:
YYMMDD-hhmmssSSS (length is 16)
The timestamp is a number of milliseconds since the Epoch (midnight
at the start of January 1, 1970, GMT). See
System.currentTimeMillis()
.
Note: This method is not thread-safe.
date
- the timestamp, in milliseconds since the Epoch, must be >=
0L
.
IllegalArgumentException
- if date < 0L
.public void format(long date, char[] buffer, int offset) throws IllegalArgumentException, NullPointerException, IndexOutOfBoundsException
CCYYMMDD-hhmmssSSS (length is 18)Otherwise, if withCentury is not set, then the format is without the century:
YYMMDD-hhmmssSSS (length is 16)
The timestamp is a number of milliseconds since the Epoch (midnight
at the start of January 1, 1970, GMT). See
System.currentTimeMillis()
.
Note: This method is not thread-safe.
date
- the timestamp, in milliseconds since the Epoch, must be >=
0L
.buffer
- the character buffer to put the formatted timestamp in, cannot be
null
.offset
- the offset into the character buffer.
IllegalArgumentException
- if date < 0L
.
NullPointerException
- if buffer == null
.
IndexOutOfBoundsException
- if offset
is invalid (less than 0
) or
incorrect (not leaving enough room for the formatter date).
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |