FormatStyle
Strategies for formatting a Date
.
- iOS
- 15.0+
- macOS
- 12.0+
- tvOS
- 15.0+
- watchOS
- 8.0+
struct FormatStyle
Strategies for formatting a Date
.
struct FormatStyle
s20FoundationEssentials4DateV0A20InternationalizationE11FormatStyleV
What are these?1J92L
import FoundationInternationalization
import FoundationEssentials
struct Date
Date
represents a single point in time.
func formatted() -> String
func formatted(date: Date.FormatStyle.DateStyle, time: Date.FormatStyle.TimeStyle) -> String
Converts self
to its textual representation that contains both the date and time parts. The exact format depends on the user’s preferences.
struct AnchoredRelativeFormatStyle
A relative format style that is detached from the system time, and instead formats an anchor date relative to the format input.
struct AttributedStyle
struct ComponentsFormatStyle
struct FormatString
struct IntervalFormatStyle
struct ParseStrategy
Options for parsing string representations of dates to create a Date
instance.
struct RelativeFormatStyle
struct VerbatimFormatStyle
Formats a Date
using the given format.
protocol Copyable
A type whose values can be implicitly or explicitly copied.
protocol CustomConsumingRegexComponent : RegexComponent
protocol Decodable
A type that can decode itself from an external representation.
protocol DiscreteFormatStyle<FormatInput, FormatOutput> : FormatStyle
A format style that transforms a continuous input into a discrete output and provides information about its discretization boundaries.
protocol Encodable
A type that can encode itself to an external representation.
protocol Equatable
A type that can be compared for value equality.
protocol Escapable
protocol FormatStyle : Decodable, Encodable, Hashable
A type that can convert a given data type into a representation.
protocol Hashable : Equatable
A type that can be hashed into a Hasher
to produce an integer hash value.
protocol ParseStrategy : Decodable, Encodable, Hashable
A type that can parse a representation of a given data type.
protocol ParseableFormatStyle : FormatStyle
A type that can convert a given data type into a representation.
protocol RegexComponent<RegexOutput>
A type that represents a regular expression.
protocol Sendable
init(date: Date.FormatStyle.DateStyle? = nil, time: Date.FormatStyle.TimeStyle? = nil, locale: Locale = .autoupdatingCurrent, calendar: Calendar = .autoupdatingCurrent, timeZone: TimeZone = .autoupdatingCurrent, capitalizationContext: FormatStyleCapitalizationContext = .unknown)
Creates a new FormatStyle
with the given configurations.
init(from decoder: any Decoder) throws
var attributed: Date.AttributedStyle { get }
Returns a type erased attributed variant of this style.
var attributedStyle: Date.FormatStyle.Attributed { get }
Return the type preserving attributed variant of this style.
var calendar: Calendar
The calendar to use for date values.
var capitalizationContext: FormatStyleCapitalizationContext
The capitalization formatting context used when formatting date and time values.
var locale: Locale
The locale to use when formatting date and time values.
var parseStrategy: Date.FormatStyle { get }
var timeZone: TimeZone
The time zone with which to specify date and time values.
func consuming(_ input: String, startingAt index: String.Index, in bounds: Range<String.Index>) throws -> (upperBound: String.Index, output: Date)?
func day(_ format: Date.FormatStyle.Symbol.Day = .defaultDigits) -> Date.FormatStyle
Change the representation of the day of the month in the format.
func dayOfYear(_ format: Date.FormatStyle.Symbol.DayOfYear = .defaultDigits) -> Date.FormatStyle
Change the representation of the day of the year in the format.
func discreteInput(after input: Date) -> Date?
func discreteInput(before input: Date) -> Date?
func encode(to encoder: any Encoder) throws
func era(_ format: Date.FormatStyle.Symbol.Era = .abbreviated) -> Date.FormatStyle
Change the representation of the era in the format.
func format(_ value: Date) -> String
func hour(_ format: Date.FormatStyle.Symbol.Hour = .defaultDigits(amPM: .abbreviated)) -> Date.FormatStyle
Change the representation of the hour in the format.
func input(after input: Date) -> Date?
func input(before input: Date) -> Date?
func locale(_ locale: Locale) -> Date.FormatStyle
func minute(_ format: Date.FormatStyle.Symbol.Minute = .defaultDigits) -> Date.FormatStyle
Change the representation of the minute in the format.
func month(_ format: Date.FormatStyle.Symbol.Month = .abbreviated) -> Date.FormatStyle
Change the representation of the month in the format.
func parse(_ value: String) throws -> Date
func quarter(_ format: Date.FormatStyle.Symbol.Quarter = .abbreviated) -> Date.FormatStyle
Change the representation of the quarter in the format.
func second(_ format: Date.FormatStyle.Symbol.Second = .defaultDigits) -> Date.FormatStyle
Change the representation of the second in the format.
func secondFraction(_ format: Date.FormatStyle.Symbol.SecondFraction) -> Date.FormatStyle
Change the representation of the second fraction in the format.
func timeZone(_ format: Date.FormatStyle.Symbol.TimeZone = .specificName(.short)) -> Date.FormatStyle
Change the representation of the time zone in the format.
func week(_ format: Date.FormatStyle.Symbol.Week = .defaultDigits) -> Date.FormatStyle
Change the representation of the week in the format.
func weekday(_ format: Date.FormatStyle.Symbol.Weekday = .abbreviated) -> Date.FormatStyle
Change the representation of the weekday in the format.
func year(_ format: Date.FormatStyle.Symbol.Year = .defaultDigits) -> Date.FormatStyle
Change the representation of the year in the format.
@dynamicMemberLookup struct Attributed
The type preserving attributed variant of this style.
struct DateStyle
Predefined date styles varied in lengths or the components included. The exact format depends on the locale.
struct Symbol
struct TimeStyle
Predefined time styles varied in lengths or the components included. The exact format depends on the locale.
typealias RegexOutput = Date
static var dateTime: Date.FormatStyle { get }
static var dateTime: Date.FormatStyle { get }
static var dateTime: Date.FormatStyle { get }
static func currency<Value>(code: String) -> Self where Self == FloatingPointFormatStyle<Value>.Currency, Value : BinaryFloatingPoint
static func currency<V>(code: String) -> Self where Self == IntegerFormatStyle<V>.Currency, V : BinaryInteger
static func fixed(format: Date.FormatString, timeZone: TimeZone, locale: Locale? = nil) -> Self where Self == Date.ParseStrategy
static func list<MemberStyle, Base>(memberStyle: MemberStyle, type: ListFormatStyle<MemberStyle, Base>.ListType, width: ListFormatStyle<MemberStyle, Base>.Width = .standard) -> Self where Self == ListFormatStyle<MemberStyle, Base>, MemberStyle : FormatStyle, Base : Sequence, MemberStyle.FormatInput == Base.Element, MemberStyle.FormatOutput == String
static func list<Base>(type: ListFormatStyle<StringStyle, Base>.ListType, width: ListFormatStyle<StringStyle, Base>.Width = .standard) -> Self where Self == ListFormatStyle<StringStyle, Base>, Base : Sequence, Base.Element == String
var regex: Regex<Self.RegexOutput> { get }
static func != (lhs: Self, rhs: Self) -> Bool
Returns a Boolean value indicating whether two values are not equal.