<!--
{
  "availability" : [
    "iOS: 4.0.0 -",
    "iPadOS: 4.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.6.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/DateFormatter/dateFormat(fromTemplate:options:locale:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSDateFormatter(cm)dateFormatFromTemplate:options:locale:"
  },
  "title" : "dateFormat(fromTemplate:options:locale:)"
}
-->

# dateFormat(fromTemplate:options:locale:)

Returns a localized date format string representing the given date format components arranged appropriately for the specified locale.

```
class func dateFormat(fromTemplate tmplate: String, options opts: Int, locale: Locale?) -> String?
```

## Parameters

`tmplate`

A string containing date format patterns (such as “MM” or “h”).

    For full details, see     [Date and Time Programming Guide](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/DatesAndTimes/DatesAndTimes.html#//apple_ref/doc/uid/10000039i)    .

`opts`

No options are currently defined.

`locale`

The locale for which the template is required.

## Return Value

A localized date format string representing the date format components given in `template`, arranged appropriately for the locale specified by `locale`. The returned string may not contain exactly those components given in `template`, but may—for example—have locale-specific adjustments applied.

## Discussion

Different locales have different conventions for the ordering of date components. You use this method to get an appropriate format string for a given set of components for a specified locale (typically you use the current locale—see [`current`](/documentation/Foundation/NSLocale/current)).

The following example shows the difference between the date formats for British and American English:

```objc
NSLocale *usLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
NSLocale *gbLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_GB"];
 
NSString *template = @"yMMMMd";
 
NSString *enDateFormat = [NSDateFormatter dateFormatFromTemplate:template options:0 locale:usLocale];
NSLog(@"Date format for %@: %@",
    [usLocale displayNameForKey:NSLocaleIdentifier value:[usLocale localeIdentifier]], enDateFormat);
 
NSString *gbDateFormat = [NSDateFormatter dateFormatFromTemplate:template options:0 locale:gbLocale];
NSLog(@"Date format for %@: %@",
    [gbLocale displayNameForKey:NSLocaleIdentifier value:[gbLocale localeIdentifier]], gbDateFormat);
 
// Output:
// Date format for English (United States): MMMM d, y
// Date format for English (United Kingdom): d MMMM y
```

---

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)