Structure
Date.FormatStyle.Symbol.Era
iOS 15.0+
iPadOS 15.0+
Mac Catalyst 15.0+
macOS 12.0+
tvOS 15.0+
watchOS 8.0+
A type that specifies a format for the era in a date format style.
struct Era
Overview
The type Date.FormatStyle.Symbol.Era includes static factory variables that create custom Date.FormatStyle.Symbol.Era objects.
Factory variable |
Description |
|---|---|
An abbreviated representation of an era. For example, |
|
A narrow era representation. For example, |
|
A full representation of an era. For example, |
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
Type Properties
static var abbreviated: Date.FormatStyle.Symbol.EraAbbreviated Era name. For example, “AD”, “Reiwa”, “令和”.static var narrow: Date.FormatStyle.Symbol.EraNarrow era name. For example, For example, “A”, “R”, “R”.static let omitted: Date.FormatStyle.Symbol.EraThe option for not including the symbol in the formatted output.static var wide: Date.FormatStyle.Symbol.EraWide era name. For example, “Anno Domini”, “Reiwa”, “令和”.
Relationships
Conforms To
Swift.EquatableSwift.HashableSwift.SendableSwift.SendableMetatype