public class FixedDateFormat
extends java.lang.Object
FixedDateFormat.FixedFormat
. For any other date patterns use FastDateFormat
.
Related benchmarks: /log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/TimeFormatBenchmark.java and /log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/ThreadsafeDateFormatBenchmark.java
Modifier and Type | Class and Description |
---|---|
static class |
FixedDateFormat.FixedFormat
Enumeration over the supported date/time format patterns.
|
Modifier and Type | Field and Description |
---|---|
private char[] |
cachedDate |
private int |
dateLength |
private int[] |
dstOffsets |
private FastDateFormat |
fastDateFormat |
private FixedDateFormat.FixedFormat |
fixedFormat |
private int |
length |
private long |
midnightToday |
private long |
midnightTomorrow |
private char |
millisSeparatorChar |
private int |
millisSeparatorLength |
private int |
secondFractionDigits |
(package private) static int[] |
TABLE |
private char |
timeSeparatorChar |
private int |
timeSeparatorLength |
private java.util.TimeZone |
timeZone |
Constructor and Description |
---|
FixedDateFormat(FixedDateFormat.FixedFormat fixedFormat,
java.util.TimeZone tz)
Constructs a FixedDateFormat for the specified fixed format.
|
FixedDateFormat(FixedDateFormat.FixedFormat fixedFormat,
java.util.TimeZone tz,
int secondFractionDigits)
Constructs a FixedDateFormat for the specified fixed format.
|
Modifier and Type | Method and Description |
---|---|
private long |
calcMidnightMillis(long time,
int addDays) |
static FixedDateFormat |
create(FixedDateFormat.FixedFormat format)
Returns a new
FixedDateFormat object for the specified FixedFormat and a TimeZone.getDefault() TimeZone. |
static FixedDateFormat |
create(FixedDateFormat.FixedFormat format,
java.util.TimeZone tz)
Returns a new
FixedDateFormat object for the specified FixedFormat and TimeZone. |
static FixedDateFormat |
createIfSupported(java.lang.String... options) |
private int |
daylightSavingTime(int hourOfDay) |
private int |
digitsLessThanThree() |
private int |
digitsMorePreciseThanMillis() |
java.lang.String |
format(long epochMillis) |
int |
format(long epochMillis,
char[] buffer,
int startPos) |
java.lang.String |
formatInstant(Instant instant) |
int |
formatInstant(Instant instant,
char[] buffer,
int startPos) |
private void |
formatNanoOfMillisecond(int nanoOfMillisecond,
char[] buffer,
int pos) |
java.lang.String |
getFormat()
Returns the full pattern of the selected fixed format.
|
java.util.TimeZone |
getTimeZone()
Returns the time zone.
|
long |
millisSinceMidnight(long currentTime)
Returns the number of milliseconds since midnight in the time zone that this
FixedDateFormat
was constructed with for the specified currentTime. |
private void |
updateCachedDate(long now) |
private void |
updateDaylightSavingTime() |
private void |
updateMidnightMillis(long now) |
private void |
writeDate(char[] buffer,
int startPos) |
private int |
writeTime(int ms,
char[] buffer,
int pos) |
private final FixedDateFormat.FixedFormat fixedFormat
private final java.util.TimeZone timeZone
private final int length
private final int secondFractionDigits
private final FastDateFormat fastDateFormat
private final char timeSeparatorChar
private final char millisSeparatorChar
private final int timeSeparatorLength
private final int millisSeparatorLength
private volatile long midnightToday
private volatile long midnightTomorrow
private final int[] dstOffsets
private char[] cachedDate
private int dateLength
static int[] TABLE
FixedDateFormat(FixedDateFormat.FixedFormat fixedFormat, java.util.TimeZone tz)
Package protected for unit tests.
fixedFormat
- the fixed formattz
- time zoneFixedDateFormat(FixedDateFormat.FixedFormat fixedFormat, java.util.TimeZone tz, int secondFractionDigits)
Package protected for unit tests.
fixedFormat
- the fixed formattz
- time zonesecondFractionDigits
- the number of digits specifying the fraction of the second to showpublic static FixedDateFormat createIfSupported(java.lang.String... options)
public static FixedDateFormat create(FixedDateFormat.FixedFormat format)
FixedDateFormat
object for the specified FixedFormat
and a TimeZone.getDefault()
TimeZone.format
- the format to useFixedDateFormat
objectpublic static FixedDateFormat create(FixedDateFormat.FixedFormat format, java.util.TimeZone tz)
FixedDateFormat
object for the specified FixedFormat
and TimeZone.format
- the format to usetz
- the time zone to useFixedDateFormat
objectpublic java.lang.String getFormat()
public java.util.TimeZone getTimeZone()
public long millisSinceMidnight(long currentTime)
Returns the number of milliseconds since midnight in the time zone that this FixedDateFormat
was constructed with for the specified currentTime.
As a side effect, this method updates the cached formatted date and the cached date demarcation timestamps when the specified current time is outside the previously set demarcation timestamps for the start or end of the current day.
currentTime
- the current time in millis since the epochprivate void updateMidnightMillis(long now)
private long calcMidnightMillis(long time, int addDays)
private void updateDaylightSavingTime()
private void updateCachedDate(long now)
public java.lang.String formatInstant(Instant instant)
public int formatInstant(Instant instant, char[] buffer, int startPos)
private int digitsLessThanThree()
private int digitsMorePreciseThanMillis()
public java.lang.String format(long epochMillis)
public int format(long epochMillis, char[] buffer, int startPos)
private void writeDate(char[] buffer, int startPos)
private int writeTime(int ms, char[] buffer, int pos)
private void formatNanoOfMillisecond(int nanoOfMillisecond, char[] buffer, int pos)
private int daylightSavingTime(int hourOfDay)