---
title: DateFormatter
framework: foundation
role: symbol
role_heading: Class
path: foundation/dateformatter
---

# DateFormatter

A formatter that converts between dates and their textual representations.

## Declaration

```swift
class DateFormatter
```

## Overview

Overview Instances of DateFormatter create string representations of NSDate objects, and convert textual representations of dates and times into NSDate objects. For user-visible representations of dates and times, DateFormatter provides a variety of localized presets and configuration options. For fixed format representations of dates and times, you can specify a custom format string. When working with date representations in ISO 8601 format, use ISO8601DateFormatter instead. To represent an interval between two NSDate objects, use DateIntervalFormatter instead. To represent a quantity of time specified by an NSDateComponents object, use DateComponentsFormatter instead. tip: In Swift, you can use Date.FormatStyle or Date.VerbatimFormatStyle rather than DateFormatter. The FormatStyle API offers a declarative idiom for customizing the formatting of various types. Also, Foundation caches identical FormatStyle instances, so you don’t need to pass them around your app, or risk wasting memory with duplicate formatters. Working With User-Visible Representations of Dates and Times When displaying a date to a user, you set the dateStyle and timeStyle properties of the date formatter according to your particular needs. For example, if you want to show the month, day, and year without showing the time, you would set the dateStyle property to DateFormatter.Style.long and the timeStyle property to DateFormatter.Style.none. Conversely, if you want to show only the time, you would set the dateStyle property to DateFormatter.Style.none and the timeStyle property to DateFormatter.Style.short. Based on the values of the dateStyle and timeStyle properties, DateFormatter provides a representation of a specified date that is appropriate for a given locale. If you need to define a format that cannot be achieved using the predefined styles, you can use the setLocalizedDateFormatFromTemplate(_:) to specify a localized date format from a template. Working With Fixed Format Date Representations important: In macOS 10.12 and later or iOS 10 and later, use the ISO8601DateFormatter class when working with ISO 8601 date representations. When working with fixed format dates, such as RFC 3339, you set the dateFormat property to specify a format string. For most fixed formats, you should also set the locale property to a POSIX locale ("en_US_POSIX"), and set the timeZone property to UTC. For more information, see Technical Q&A QA1480 “NSDateFormatter and Internet Dates”. Thread Safety On iOS 7 and later NSDateFormatter is thread safe. In macOS 10.9 and later NSDateFormatter is thread safe so long as you are using the modern behavior in a 64-bit app. On earlier versions of the operating system, or when using the legacy formatter behavior or running in 32-bit in macOS, NSDateFormatter is not thread safe, and you therefore must not mutate a date formatter simultaneously from multiple threads.

## Topics

### Converting Objects

- [date(from:)](foundation/dateformatter/date(from:).md)
- [string(from:)](foundation/dateformatter/string(from:).md)
- [localizedString(from:dateStyle:timeStyle:)](foundation/dateformatter/localizedstring(from:datestyle:timestyle:).md)
- [getObjectValue(_:for:range:)](foundation/dateformatter/getobjectvalue(_:for:range:).md)

### Managing Formats and Styles

- [dateStyle](foundation/dateformatter/datestyle.md)
- [timeStyle](foundation/dateformatter/timestyle.md)
- [dateFormat](foundation/dateformatter/dateformat.md)
- [setLocalizedDateFormatFromTemplate(_:)](foundation/dateformatter/setlocalizeddateformatfromtemplate(_:).md)
- [dateFormat(fromTemplate:options:locale:)](foundation/dateformatter/dateformat(fromtemplate:options:locale:).md)
- [formattingContext](foundation/dateformatter/formattingcontext.md)

### Managing Attributes

- [calendar](foundation/dateformatter/calendar.md)
- [defaultDate](foundation/dateformatter/defaultdate.md)
- [locale](foundation/dateformatter/locale.md)
- [timeZone](foundation/dateformatter/timezone.md)
- [twoDigitStartDate](foundation/dateformatter/twodigitstartdate.md)
- [gregorianStartDate](foundation/dateformatter/gregorianstartdate.md)

### Managing Behavior Version

- [formatterBehavior](foundation/dateformatter/formatterbehavior.md)
- [defaultFormatterBehavior](foundation/dateformatter/defaultformatterbehavior.md)

### Managing Natural Language Support

- [isLenient](foundation/dateformatter/islenient.md)
- [doesRelativeDateFormatting](foundation/dateformatter/doesrelativedateformatting.md)

### Managing AM and PM Symbols

- [amSymbol](foundation/dateformatter/amsymbol.md)
- [pmSymbol](foundation/dateformatter/pmsymbol.md)

### Managing Weekday Symbols

- [weekdaySymbols](foundation/dateformatter/weekdaysymbols.md)
- [shortWeekdaySymbols](foundation/dateformatter/shortweekdaysymbols.md)
- [veryShortWeekdaySymbols](foundation/dateformatter/veryshortweekdaysymbols.md)
- [standaloneWeekdaySymbols](foundation/dateformatter/standaloneweekdaysymbols.md)
- [shortStandaloneWeekdaySymbols](foundation/dateformatter/shortstandaloneweekdaysymbols.md)
- [veryShortStandaloneWeekdaySymbols](foundation/dateformatter/veryshortstandaloneweekdaysymbols.md)

### Managing Month Symbols

- [monthSymbols](foundation/dateformatter/monthsymbols.md)
- [shortMonthSymbols](foundation/dateformatter/shortmonthsymbols.md)
- [veryShortMonthSymbols](foundation/dateformatter/veryshortmonthsymbols.md)
- [standaloneMonthSymbols](foundation/dateformatter/standalonemonthsymbols.md)
- [shortStandaloneMonthSymbols](foundation/dateformatter/shortstandalonemonthsymbols.md)
- [veryShortStandaloneMonthSymbols](foundation/dateformatter/veryshortstandalonemonthsymbols.md)

### Managing Quarter Symbols

- [quarterSymbols](foundation/dateformatter/quartersymbols.md)
- [shortQuarterSymbols](foundation/dateformatter/shortquartersymbols.md)
- [standaloneQuarterSymbols](foundation/dateformatter/standalonequartersymbols.md)
- [shortStandaloneQuarterSymbols](foundation/dateformatter/shortstandalonequartersymbols.md)

### Managing Era Symbols

- [eraSymbols](foundation/dateformatter/erasymbols.md)
- [longEraSymbols](foundation/dateformatter/longerasymbols.md)

### Deprecated

- [generatesCalendarDates](foundation/dateformatter/generatescalendardates.md)

### Constants

- [DateFormatter.Style](foundation/dateformatter/style.md)
- [DateFormatter.Behavior](foundation/dateformatter/behavior.md)

## Relationships

### Inherits From

- [Formatter](foundation/formatter.md)

### Conforms To

- [CVarArg](swift/cvararg.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Equatable](swift/equatable.md)
- [Hashable](swift/hashable.md)
- [NSCoding](foundation/nscoding.md)
- [NSCopying](foundation/nscopying.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)
- [Sendable](swift/sendable.md)
- [SendableMetatype](swift/sendablemetatype.md)

## See Also

### Dates and times

- [DateComponentsFormatter](foundation/datecomponentsformatter.md)
- [RelativeDateTimeFormatter](foundation/relativedatetimeformatter.md)
- [DateIntervalFormatter](foundation/dateintervalformatter.md)
- [ISO8601DateFormatter](foundation/iso8601dateformatter.md)
