---
title: "string(from:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/datecomponentsformatter/string(from:)-9exxn"
---

# string(from:)

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

## Declaration

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

## Parameters

- `components`: A date components object containing the date and time information to format. The doc://com.apple.foundation/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

Return Value A formatted string representing the specified date information.

## Discussion

Discussion Use this method to format date information that is already broken down into the component day and time values.

## See Also

### Formatting Values

- [string(for:)](foundation/datecomponentsformatter/string(for:).md)
- [string(from:to:)](foundation/datecomponentsformatter/string(from:to:).md)
- [string(from:)](foundation/datecomponentsformatter/string(from:)-7sj4j.md)
- [localizedString(from:unitsStyle:)](foundation/datecomponentsformatter/localizedstring(from:unitsstyle:).md)
