Skip to content

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

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

Type Properties

Relationships

Conforms To

  • Swift.Equatable
  • Swift.Hashable
  • Swift.Sendable
  • Swift.SendableMetatype