StructureFoundationInternationalization
Date.FormatStyle.DateStyle
iOS 15.0+
iPadOS 15.0+
Mac Catalyst 15.0+
macOS 12.0+
tvOS 15.0+
watchOS 8.0+
Type that defines date styles varied in length or components included.
struct DateStyle
Overview
The exact format depends on the locale. Possible values of date style include omitted, numeric, abbreviated, long, and complete.
The following code sample shows a variety of date style format results using the en_US locale.
let meetingDate = Date()
meetingDate.formatted(date: .omitted, time: .standard)
// 9:42:14 AM
meetingDate.formatted(date: .numeric, time: .omitted)
// 10/17/2020
meetingDate.formatted(date: .abbreviated, time: .omitted)
// Oct 17, 2020
meetingDate.formatted(date: .long, time: .omitted)
// October 17, 2020
meetingDate.formatted(date: .complete, time: .omitted)
// Saturday, October 17, 2020
meetingDate.formatted()
// 10/17/2020, 9:42 AM
The default date style is numeric.
Topics
Initializers
Type Properties
static let abbreviated: Date.FormatStyle.DateStyleShows date components in their abbreviated form if possible. For example, “Oct 21, 2015”.static let complete: Date.FormatStyle.DateStyleShows the complete day. For example, “Wednesday, October 21, 2015”.static let long: Date.FormatStyle.DateStyleShows date components in their long form if possible. For example, “October 21, 2015”.static let numeric: Date.FormatStyle.DateStyleShows date components in their numeric form. For example, “10/21/2015”.static let omitted: Date.FormatStyle.DateStyleExcludes the date part.
Relationships
Conforms To
Swift.DecodableSwift.EncodableSwift.EquatableSwift.HashableSwift.SendableSwift.SendableMetatype