<!--
{
  "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/DateComponentsFormatter/string(from:)-9exxn",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSDateComponentsFormatter(im)stringFromDateComponents:"
  },
  "title" : "string(from:)"
}
-->

# string(from:)

Returns a formatted string based on the specified date component information.

```
func string(from components: DateComponents) -> String?
```

## Parameters

`components`

A date components object containing the date and time information to format. The [`allowedUnits`](/documentation/Foundation/DateComponentsFormatter/allowedUnits) property determines which date components are actually used to generate the string. All other date components are ignored. This parameter must not be `nil`.

## Return Value

A formatted string representing the specified date information.

## Discussion

Use this method to format date information that is already broken down into the component day 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)