Class FixedDateFormat
- java.lang.Object
-
- org.apache.logging.log4j.core.util.datetime.FixedDateFormat
-
public class FixedDateFormat extends Object
Custom time formatter that trades flexibility for performance. This formatter only supports the date patterns defined inFixedDateFormat.FixedFormat
. For any other date patterns useFastDateFormat
.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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
FixedDateFormat.FixedFormat
Enumeration over the supported date/time format patterns.static class
FixedDateFormat.FixedTimeZoneFormat
Fixed time zone formats.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static FixedDateFormat
create(FixedDateFormat.FixedFormat format)
Returns a newFixedDateFormat
object for the specifiedFixedFormat
and aTimeZone.getDefault()
TimeZone.static FixedDateFormat
create(FixedDateFormat.FixedFormat format, TimeZone tz)
Returns a newFixedDateFormat
object for the specifiedFixedFormat
and TimeZone.static FixedDateFormat
createIfSupported(String... options)
String
format(long epochMillis)
int
format(long epochMillis, char[] buffer, int startPos)
String
formatInstant(Instant instant)
int
formatInstant(Instant instant, char[] buffer, int startPos)
String
getFormat()
Returns the full pattern of the selected fixed format.TimeZone
getTimeZone()
Returns the time zone.long
millisSinceMidnight(long currentTime)
Returns the number of milliseconds since midnight in the time zone that thisFixedDateFormat
was constructed with for the specified currentTime.
-
-
-
Method Detail
-
createIfSupported
public static FixedDateFormat createIfSupported(String... options)
-
create
public static FixedDateFormat create(FixedDateFormat.FixedFormat format)
Returns a newFixedDateFormat
object for the specifiedFixedFormat
and aTimeZone.getDefault()
TimeZone.- Parameters:
format
- the format to use- Returns:
- a new
FixedDateFormat
object
-
create
public static FixedDateFormat create(FixedDateFormat.FixedFormat format, TimeZone tz)
Returns a newFixedDateFormat
object for the specifiedFixedFormat
and TimeZone.- Parameters:
format
- the format to usetz
- the time zone to use- Returns:
- a new
FixedDateFormat
object
-
getFormat
public String getFormat()
Returns the full pattern of the selected fixed format.- Returns:
- the full date-time pattern
-
getTimeZone
public TimeZone getTimeZone()
Returns the time zone.- Returns:
- the time zone
-
millisSinceMidnight
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.
- Parameters:
currentTime
- the current time in millis since the epoch- Returns:
- the number of milliseconds since midnight for the specified time
-
formatInstant
public int formatInstant(Instant instant, char[] buffer, int startPos)
-
format
public String format(long epochMillis)
-
format
public int format(long epochMillis, char[] buffer, int startPos)
-
-