The formatting strategies available for formatting dates when encoding a date as JSON.


enum JSONEncoder.DateEncodingStrategy


Default Formats

case deferredToDate

The strategy that uses formatting from the Date structure.

Standard Formats

case iso8601

The strategy that formats dates according to the ISO 8601 and RFC 3339 standards.

Custom Formats

case formatted(DateFormatter)

The strategy that defers formatting settings to a supplied date formatter.

case custom((Date, Encoder) -> Void)

The strategy that formats custom dates by calling a user-defined function.

Epoch Formats

case millisecondsSince1970

The strategy that encodes dates in terms of milliseconds since midnight UTC on January 1, 1970.

case secondsSince1970

The strategy that encodes dates in terms of seconds since midnight UTC on January 1, 1970.

See Also

Encoding Dates

var dateEncodingStrategy: JSONEncoder.DateEncodingStrategy

The strategy used when encoding dates as part of a JSON object.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software