ISO8601FormatStyle
Options for generating and parsing string representations of dates following the ISO 8601 standard.
- iOS
- 15.0+
- macOS
- 12.0+
- tvOS
- 15.0+
- watchOS
- 8.0+
struct ISO8601FormatStyle
Options for generating and parsing string representations of dates following the ISO 8601 standard.
struct ISO8601FormatStyle
import FoundationEssentials
struct Date
Date
represents a single point in time.
init()
Returns a Date
initialized to the current date and time.
init<T>(_ value: T.ParseInput, strategy: T) throws where T : ParseStrategy, T.ParseOutput == Date
init<T, Value>(_ value: Value, strategy: T) throws where T : ParseStrategy, Value : StringProtocol, T.ParseInput == String, T.ParseOutput == Date
init(from decoder: any Decoder) throws
init(timeInterval: TimeInterval, since date: Date)
Returns a Date
initialized relative to another given date by a given number of seconds.
init(timeIntervalSince1970: TimeInterval)
Returns a Date
initialized relative to 00:00:00 UTC on 1 January 1970 by a given number of seconds.
init(timeIntervalSinceNow: TimeInterval)
Returns a Date
initialized relative to the current date and time by a given number of seconds.
init(timeIntervalSinceReferenceDate ti: TimeInterval)
Returns a Date
initialized relative to 00:00:00 UTC on 1 January 2001 by a given number of seconds.
static let distantFuture: Date
Creates and returns a Date value representing a date in the distant future.
static let distantPast: Date
Creates and returns a Date value representing a date in the distant past.
static var now: Date { get }
Returns a Date
initialized to the current date and time.
static let timeIntervalBetween1970AndReferenceDate: TimeInterval
The number of seconds from 1 January 1970 to the reference date, 1 January 2001.
static var timeIntervalSinceReferenceDate: TimeInterval { get }
The interval between 00:00:00 UTC on 1 January 2001 and the current date and time.
static let validCalendarRange: ClosedRange<Date>
var capped: Date { get }
var customMirror: Mirror { get }
var debugDescription: String { get }
var description: String { get }
A string representation of the date object (read-only). The representation is useful for debugging only. There are a number of options to acquire a formatted string for a date including: date formatters (see NSDateFormatter and Data Formatting Guide), and the Date
function description(locale:)
.
var isValidForEnumeration: Bool { get }
var nextDown: Date { get }
var nextUp: Date { get }
var timeIntervalSince1970: TimeInterval { get }
The interval between the date object and 00:00:00 UTC on 1 January 1970.
var timeIntervalSinceNow: TimeInterval { get }
The time interval between the date and the current date and time.
var timeIntervalSinceReferenceDate: TimeInterval { get }
Returns the interval between the date object and 00:00:00 UTC on 1 January 2001.
static func + (lhs: Date, rhs: TimeInterval) -> Date
Returns a Date
with a specified amount of time added to it.
static func += (lhs: inout Date, rhs: TimeInterval)
Add a TimeInterval
to a Date
.
static func - (lhs: Date, rhs: TimeInterval) -> Date
Returns a Date
with a specified amount of time subtracted from it.
static func -= (lhs: inout Date, rhs: TimeInterval)
Subtract a TimeInterval
from a Date
.
static func < (lhs: Date, rhs: Date) -> Bool
Returns true if the left hand Date
is earlier in time than the right hand Date
.
static func == (lhs: Date, rhs: Date) -> Bool
Returns true if the two Date
values represent the same point in time.
static func > (lhs: Date, rhs: Date) -> Bool
Returns true if the left hand Date
is later in time than the right hand Date
.
func ISO8601Format(_ style: Date.ISO8601FormatStyle = .init()) -> String
mutating func addTimeInterval(_ timeInterval: TimeInterval)
Add a TimeInterval
to this Date
.
func addingTimeInterval(_ timeInterval: TimeInterval) -> Date
Return a new Date
by adding a TimeInterval
to this Date
.
func advanced(by n: TimeInterval) -> Date
func compare(_ other: Date) -> ComparisonResult
Compare two Date
values.
func description(with locale: Locale?) -> String
Returns a string representation of the receiver using the given locale.
func distance(to other: Date) -> TimeInterval
func encode(to encoder: any Encoder) throws
func formatted<F>(_ format: F) -> F.FormatOutput where F : FormatStyle, F.FormatInput == Date
func hash(into hasher: inout Hasher)
func timeIntervalSince(_ date: Date) -> TimeInterval
Returns the interval between the receiver and another given date.
typealias Stride = TimeInterval
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 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(dateSeparator: Date.ISO8601FormatStyle.DateSeparator = .dash, dateTimeSeparator: Date.ISO8601FormatStyle.DateTimeSeparator = .standard, timeSeparator: Date.ISO8601FormatStyle.TimeSeparator = .colon, timeZoneSeparator: Date.ISO8601FormatStyle.TimeZoneSeparator = .omitted, includingFractionalSeconds: Bool = false, timeZone: TimeZone = TimeZone(secondsFromGMT: 0)!)
init(dateSeparator: Date.ISO8601FormatStyle.DateSeparator = .dash, dateTimeSeparator: Date.ISO8601FormatStyle.DateTimeSeparator = .standard, timeZone: TimeZone = TimeZone(secondsFromGMT: 0)!)
init(from decoder: any Decoder) throws
var dateSeparator: Date.ISO8601FormatStyle.DateSeparator { get }
var dateTimeSeparator: Date.ISO8601FormatStyle.DateTimeSeparator { get }
var formatFields: Date.ISO8601FormatStyle.Fields { get }
var includingFractionalSeconds: Bool { get }
var parseStrategy: Date.ISO8601FormatStyle { get }
var timeSeparator: Date.ISO8601FormatStyle.TimeSeparator { get }
var timeZone: TimeZone { get set }
The time zone to use to create and parse date representations.
var timeZoneSeparator: Date.ISO8601FormatStyle.TimeZoneSeparator { get }
static func == (lhs: Date.ISO8601FormatStyle, rhs: Date.ISO8601FormatStyle) -> Bool
func consuming(_ input: String, startingAt index: String.Index, in bounds: Range<String.Index>) throws -> (upperBound: String.Index, output: Date)?
func dateSeparator(_ separator: Date.ISO8601FormatStyle.DateSeparator) -> Date.ISO8601FormatStyle
func dateTimeSeparator(_ separator: Date.ISO8601FormatStyle.DateTimeSeparator) -> Date.ISO8601FormatStyle
func day() -> Date.ISO8601FormatStyle
func encode(to encoder: any Encoder) throws
func format(_ value: Date) -> String
func hash(into hasher: inout Hasher)
func month() -> Date.ISO8601FormatStyle
func parse(_ value: String) throws -> Date
func parse(_ value: String, in range: Range<String.Index>) -> (String.Index, Date)?
func time(includingFractionalSeconds: Bool) -> Date.ISO8601FormatStyle
func timeSeparator(_ separator: Date.ISO8601FormatStyle.TimeSeparator) -> Date.ISO8601FormatStyle
func timeZone(separator: Date.ISO8601FormatStyle.TimeZoneSeparator) -> Date.ISO8601FormatStyle
func timeZoneSeparator(_ separator: Date.ISO8601FormatStyle.TimeZoneSeparator) -> Date.ISO8601FormatStyle
func weekOfYear() -> Date.ISO8601FormatStyle
func year() -> Date.ISO8601FormatStyle
enum DateSeparator
enum DateTimeSeparator
struct Fields
enum TimeSeparator
enum TimeZoneSeparator
typealias RegexOutput = Date
static var iso8601: Date.ISO8601FormatStyle { get }
static var iso8601: Date.ISO8601FormatStyle { get }
static var iso8601: Date.ISO8601FormatStyle { get }
static var iso8601: Date.ISO8601FormatStyle { get }
Creates a regex component to match an ISO 8601 date and time, such as “2015-11-14’T’15:05:03’Z’”, and capture the string as a Date
using the time zone as specified in the string.
static func iso8601(timeZone: TimeZone, includingFractionalSeconds: Bool = false, dateSeparator: Date.ISO8601FormatStyle.DateSeparator = .dash, dateTimeSeparator: Date.ISO8601FormatStyle.DateTimeSeparator = .standard, timeSeparator: Date.ISO8601FormatStyle.TimeSeparator = .colon) -> Self
Creates a regex component to match an ISO 8601 date and time string without time zone, and capture the string as a Date
using the specified timeZone
. If the string contains time zone designators, matches up until the start of time zone designators.
static func iso8601Date(timeZone: TimeZone, dateSeparator: Date.ISO8601FormatStyle.DateSeparator = .dash) -> Self
Creates a regex component to match an ISO 8601 date string, such as “2015-11-14”, and capture the string as a Date
. The captured Date
would be at midnight in the specified timeZone
.
static func iso8601WithTimeZone(includingFractionalSeconds: Bool = false, dateSeparator: Date.ISO8601FormatStyle.DateSeparator = .dash, dateTimeSeparator: Date.ISO8601FormatStyle.DateTimeSeparator = .standard, timeSeparator: Date.ISO8601FormatStyle.TimeSeparator = .colon, timeZoneSeparator: Date.ISO8601FormatStyle.TimeZoneSeparator = .omitted) -> Self
Creates a regex component to match an ISO 8601 date and time string, including time zone, and capture the string as a Date
using the time zone as specified in the 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.
func locale(_ locale: Locale) -> Self
import Foundation
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