<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.10.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/DateIntervalFormatter",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSDateIntervalFormatter"
  },
  "title" : "DateIntervalFormatter"
}
-->

# DateIntervalFormatter

A formatter that creates string representations of time intervals.

```
class DateIntervalFormatter
```

## Overview

A [`DateIntervalFormatter`](/documentation/Foundation/DateIntervalFormatter) 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:to:)`](/documentation/Foundation/DateIntervalFormatter/string(from:to:)) 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”.

Configuring a formatter object

```objc
NSDateIntervalFormatter* formatter = [[NSDateIntervalFormatter alloc] init];
formatter.dateStyle = NSDateIntervalFormatterShortStyle;
formatter.timeStyle = NSDateIntervalFormatterNoStyle;
 
// Create two dates that are exactly 1 day apart.
NSDate* startDate = [NSDate date];
NSDate* endDate = [NSDate dateWithTimeInterval:86400 sinceDate:startDate];
 
// Use the configured formatter to generate the string.
NSString* outputString = [formatter stringFromDate:startDate toDate:endDate];
```

> Note:
> Always set to the ``doc://com.apple.foundation/documentation/Foundation/DateIntervalFormatter/dateStyle`` and ``doc://com.apple.foundation/documentation/Foundation/DateIntervalFormatter/timeStyle`` properties to appropriate values before generating any strings.

The [`string(from:to:)`](/documentation/Foundation/DateIntervalFormatter/string(from:to:)) 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.

> Tip:
> In Swift, you can use ``doc://com.apple.foundation/documentation/Foundation/Date/IntervalFormatStyle`` rather than ``doc://com.apple.foundation/documentation/Foundation/DateIntervalFormatter``. The ``doc://com.apple.foundation/documentation/Foundation/FormatStyle`` API offers a declarative idiom for customizing the formatting of various types. Also, Foundation caches identical ``doc://com.apple.foundation/documentation/Foundation/FormatStyle`` instances, so you don’t need to pass them around your app, or risk wasting memory with duplicate formatters.

## Topics

### Formatting a String

[`string(from:to:)`](/documentation/Foundation/DateIntervalFormatter/string(from:to:))

Returns a formatted string based on the specified start and end dates.

### Configuring the Formatter Options

[`dateStyle`](/documentation/Foundation/DateIntervalFormatter/dateStyle)

The style to use when formatting day, month, and year information.

[`timeStyle`](/documentation/Foundation/DateIntervalFormatter/timeStyle)

The style to use when formatting hour, minute, and second information.

[`dateTemplate`](/documentation/Foundation/DateIntervalFormatter/dateTemplate)

The template for formatting one date and time value.

[`calendar`](/documentation/Foundation/DateIntervalFormatter/calendar)

The calendar to use for date values.

[`locale`](/documentation/Foundation/DateIntervalFormatter/locale)

The locale to use when formatting date and time values.

[`timeZone`](/documentation/Foundation/DateIntervalFormatter/timeZone)

The time zone with which to specify time values.

### Constants

[`DateIntervalFormatter.Style`](/documentation/Foundation/DateIntervalFormatter/Style)

Formatting styles for individual date and time values.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)