Contents

Date.FormatStyle.Symbol.Era

A type that specifies a format for the era in a date format style.

Declaration

struct Era

Overview

The type Date.FormatStyle.Symbol.Era includes static factory variables that create custom Date.FormatStyle.Symbol.Era objects.

Factory variable

Description

Abbreviated

An abbreviated representation of an era. For example, AD, BC.

Narrow

A narrow era representation. For example, A, B.

Wide

A full representation of an era. For example, Anno Domini, Before Christ.

To customize the era format in a string representation of a Date, use era(_:). The following example shows a variety of Date.FormatStyle.Symbol.Era format styles applied to a date.

let meetingDate = Date() // Feb 9, 2021 at 3:00 PM
meetingDate.formatted(Date.FormatStyle().era(.abbreviated)) // AD
meetingDate.formatted(Date.FormatStyle().era(.narrow)) // A
meetingDate.formatted(Date.FormatStyle().era(.wide)) // Anno Domini
meetingDate.formatted(Date.FormatStyle().era()) // AD

If no format is specified as a parameter, the abbreviated static variable is the default format.

For more information about formatting dates, see the Date.FormatStyle.

Topics

Modifying an Era

Comparing an Era

Type Properties

See Also

Modifying Date Style Format Symbols