public final class UtlTime extends Object
This class IS supported for use by end users.
Modifier and Type | Field and Description |
---|---|
static String |
PROP_TIME_FORMAT
Deprecated.
Use
UtlConstants.TIME_FORMAT_PROPNAME instead. |
static String |
PROP_TIME_FORMAT_DEFAULT
Deprecated.
Use
UtlConstants.TIME_FORMAT_DEFAULT instead. |
static String |
PROP_TIME_TIMEZONEFORMAT
Deprecated.
Use
UtlConstants.TIME_TIMEZONEFORMAT_PROPNAME instead. |
static String |
PROP_TIME_TIMEZONEFORMAT_DEFAULT
Deprecated.
Use
UtlConstants.TIME_TIMEZONEFORMAT_DEFAULT instead. |
static String |
PROP_TIME_USEEPOCHOFFSET
Deprecated.
Use
UtlConstants.TIME_USEEPOCHOFFSET_PROPNAME instead. |
static String |
PROP_TIME_USENATIVE
Deprecated.
Use
UtlConstants.TIME_USENATIVE_PROPNAME instead. |
static boolean |
PROP_TIME_USENATIVE_DEFAULT
Deprecated.
Use
UtlConstants.TIME_USENATIVE_DEFAULT instead. |
Constructor and Description |
---|
UtlTime() |
Modifier and Type | Method and Description |
---|---|
static void |
cleanupFormatter()
Cleans up the calling thread's
ThreadLocal DateFormat |
static String |
format(Date date)
Formats the given date using the current default timestamp format via
a
ThreadLocal DateFormat instance. |
static DateFormat |
getCachedTimestampFormatter()
Get's the thread local cached, timestamp formatter with the
current timestamp formatting settings.
|
static String |
getTimestampFormat()
Returns the current default timestamp format string
|
static DateFormat |
getTimestampFormatter()
Constructs a new DateFormat using the
getTimestampFormat()
and
and dateFormatTimeZone. |
static TimeZone |
getTimestampFormatTimeZone()
Returns the current default timestamp format string
|
static boolean |
isEpochOffset()
Deprecated.
|
static boolean |
isEpochOffsetTimeEnabled()
Tests whether the time returned by
now() is the number of microseconds from the epoch. |
static boolean |
isNativeTimeEnabled() |
static void |
main(String[] args)
Prints the current time, suffixed with microseconds.
|
static long |
now()
Return the current time in microseconds.
|
static long |
nowSinceEpoch()
Return the current wall time in microseconds.
|
static Date |
parse(String timestamp)
Attempts to parse the provide timestamp as a Date using the current
timezone format.
|
static void |
setTimestampFormat(String dateFormat)
Sets the default timestamp format which is used by various platform components.
|
static TimeZone |
setTimestampFormatTimeZone(String timezone)
Sets the default date format timezone which is used by various platform components
Note, that this will not affect components that have already retrieved the a
dateformat unless those components resample the timezoneFormat
This method looks up the timezone using
TimeZone.getTimeZone(String) which
will default the timezone to 'GMT' if the given timezone is not valid. |
static void |
setTimestampFormatTimeZone(TimeZone timezone)
Sets the default date format timezone which is used by various platform components
Note, that this will not affect components that have already retrieved the a
dateformat unless those components resample the timezoneFormat
|
@Deprecated public static final String PROP_TIME_USENATIVE
UtlConstants.TIME_USENATIVE_PROPNAME
instead.@Deprecated public static final boolean PROP_TIME_USENATIVE_DEFAULT
UtlConstants.TIME_USENATIVE_DEFAULT
instead.@Deprecated public static final String PROP_TIME_FORMAT
UtlConstants.TIME_FORMAT_PROPNAME
instead.@Deprecated public static final String PROP_TIME_FORMAT_DEFAULT
UtlConstants.TIME_FORMAT_DEFAULT
instead.@Deprecated public static final String PROP_TIME_TIMEZONEFORMAT
UtlConstants.TIME_TIMEZONEFORMAT_PROPNAME
instead.@Deprecated public static final String PROP_TIME_TIMEZONEFORMAT_DEFAULT
UtlConstants.TIME_TIMEZONEFORMAT_DEFAULT
instead.@Deprecated public static final String PROP_TIME_USEEPOCHOFFSET
UtlConstants.TIME_USEEPOCHOFFSET_PROPNAME
instead.@Deprecated public static final boolean isEpochOffset()
isEpochOffsetTimeEnabled()
public static final boolean isNativeTimeEnabled()
public static final boolean isEpochOffsetTimeEnabled()
now()
is the number of microseconds from the epoch.
If the system is configured with UtlConstants.TIME_USEEPOCHOFFSET_PROPNAME
set to true
the returned timestamp will represent the number of microseconds since the
epoch. In such cases one can do new Date(UtlTime.now() / 1000) and arrive
at a valid date. See UtlConstants.TIME_USEEPOCHOFFSET_PROPNAME
for information on the
provided resolution of the timestamp.
public static final long now()
In general the time returned by the method can only be used to measure elapsed time and is not related to any other notion of system or wall-clock time.
The timestamp returned depends on how the system is configured.
isEpochOffsetTimeEnabled()
== true
then this method returns nowSinceEpoch()
.
isNativeTimeEnabled()
== true
then the platform may use platform specific native
apis to return the time which returns a microsecond resolution wall time.
System.nanoTime()
/ 1000.
public static final long nowSinceEpoch()
This method returns a wall clock adjusted number of microseconds since the epoch with
microsecond precision, but with an accuracy limited to that of System.currentTimeMillis()
.
Subsequent calls to to this method can be used to compute the elapsed number of microseconds
between the 2 calls, but the value returned here cannot be reliably compared to values
obtained in another process even on the same host with anything but millisecond
precision unless native time
is enabled and suppported.
Unlike a timestamp returned by something like
one
can do System.nanoTime()
/ 1000new Date(UtlTime.nowSinceEpoch() / 1000)
and arrive at a valid date. This makes this
method useful both for measuring elapsed time at microsend resolution and recording timestamps that can
be compared to wall time.
Note that when isNativeTimeEnabled()
== true
, the value of
"nv.time.useepochoffset"
is ignored in favor
of the wall time provided by native time. In this case timestamps are comparable across
two processes on the same host, and the accuracy of the timestamp is dictated by the accuracy of
the underlying hardware clock.
public static final void setTimestampFormat(String dateFormat)
dateFormat
- The date format to be used by getTimestampFormatter()
IllegalArgumentException
- if the dateFormat is not validpublic static final String getTimestampFormat()
public static final void setTimestampFormatTimeZone(TimeZone timezone)
timezone
- The time zone to be used by getTimestampFormat()
public static final TimeZone setTimestampFormatTimeZone(String timezone)
This method looks up the timezone using TimeZone.getTimeZone(String)
which
will default the timezone to 'GMT' if the given timezone is not valid.
timezone
- The time zone to be used by getTimestampFormatter()
TimeZone
that was set.public static final TimeZone getTimestampFormatTimeZone()
public static final DateFormat getTimestampFormatter()
getTimestampFormat()
and
and dateFormatTimeZone.public static final String format(Date date)
ThreadLocal
DateFormat
instance. Callers of this mehod
should call cleanupFormatter()
before the the calling thread
is stopped.date
- The date to format.public static final Date parse(String timestamp) throws ParseException
timestamp
- The timestamp to parseParseException
- if there is an error parsing the timestamppublic static final DateFormat getCachedTimestampFormatter()
public static final void cleanupFormatter()
ThreadLocal
DateFormat
public static final void main(String[] args)
args
- Argumens (unused).Copyright © 2019 Neeve Research, LLC. All Rights Reserved.