A formatter that creates string representations of time intervals.
- iOS 8.0+
- macOS 10.10+
- tvOS 9.0+
- watchOS 2.0+
Date object creates user-readable strings from pairs of dates. Use a date interval formatter to create user-readable strings of the form <start>
- <end> for your app’s interface, where <start> and <end> are date values that you supply. The formatter uses locale and language information, along with custom formatting options, to define the content of the resulting string. You can specify different styles for the date and time information in each date value.
To use this class, create an instance, configure its properties, and call the
string(from: method to generate a string. The properties of this class let you configure the calendar and specify the style to apply to date and time values. Given a current date of January 16, 2015, Configuring the Formatter Options shows how to configure a formatter object and generate the string “1/16/15 - 1/17/15”.
string(from: method may be called safely from any thread of your app. It is also safe to share a single instance of this class from multiple threads, with the caveat that you should not change the configuration of the object while another thread is using it to generate a string.