public final class JsonDateFormat extends java.lang.Object
Formats java.util.Date and java.util.Calendar values for JSON the way Jackson's default
StdDateFormat does, which is how Spring Boot renders them: a UTC instant that always has
millisecond precision and a Z suffix, e.g. 2024-06-15T14:30:45.000Z.
Works from epoch milliseconds, so java.sql.Date, java.sql.Time and
java.sql.Timestamp (whose sub-millisecond nanos are dropped) format the same way as a plain
Date; java.sql.Date#toInstant() and java.sql.Time#toInstant() would throw.
Fields are read from a java.util.GregorianCalendar, the calendar system of java.util.Date, so
dates before the 1582 Gregorian cutover use the Julian calendar. Years after 9999 get a +
sign and years before 1 AD use ISO 8601 numbering (1 BC is +0000, 2 BC is -0001).
| Type Params | Return Type | Name and description |
|---|---|---|
|
public static java.lang.String |
format(long epochMillis)
|
|
public static java.lang.String |
format(long epochMillis, java.util.TimeZone zone)Formats in a time zone, as Jackson does when a default time zone is configured (Spring Boot's spring.jackson.time-zone): the local date and time in the zone followed by its offset,
e.g. |
|
public static java.lang.String |
formatKey(java.lang.Object key)The JSON object key Jackson (and so Spring Boot) writes for a map key: a java.util.Date (including the java.sql types) or java.util.Calendar key is formatted as by
format(long), a java.time.ZonedDateTime key with
java.time.format.DateTimeFormatter#ISO_OFFSET_DATE_TIME, and any other key with toString(). |
|
public static boolean |
isDateKey(java.lang.Object key)Whether Jackson writes a map key of this type differently from its toString(). |
| Methods inherited from class | Name |
|---|---|
class java.lang.Object |
java.lang.Object#equals(java.lang.Object), java.lang.Object#getClass(), java.lang.Object#hashCode(), java.lang.Object#notify(), java.lang.Object#notifyAll(), java.lang.Object#toString(), java.lang.Object#wait(), java.lang.Object#wait(long), java.lang.Object#wait(long, int) |
epochMillis - milliseconds since 1970-01-01T00:00:00Z2024-06-15T14:30:45.123Z Formats in a time zone, as Jackson does when a default time zone is configured (Spring Boot's
spring.jackson.time-zone): the local date and time in the zone followed by its offset,
e.g. 2024-06-15T10:30:45.123-04:00, or by Z where the offset is zero.
epochMillis - milliseconds since 1970-01-01T00:00:00Zzone - the time zone to write the date and time in The JSON object key Jackson (and so Spring Boot) writes for a map key: a java.util.Date
(including the java.sql types) or java.util.Calendar key is formatted as by
format(long), a java.time.ZonedDateTime key with
java.time.format.DateTimeFormatter#ISO_OFFSET_DATE_TIME, and any other key with toString().
key - a non-null map key Whether Jackson writes a map key of this type differently from its toString().
key - a map key