---
title: "localizedString(from:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/relativedatetimeformatter/localizedstring(from:)"
---

# localizedString(from:)

Formats a relative time represented by the specified date components.

## Declaration

```swift
func localizedString(from dateComponents: DateComponents) -> String
```

## Parameters

- `dateComponents`: The date components to format.

## Return Value

Return Value A string that represents the formatted relative time from date components.

## Discussion

Discussion The formatter interprets a negative component value as a date in the past. let components = DateComponents(day: -2) let formatter = RelativeDateTimeFormatter() print(formatter.localizedString(from: components)) // Outputs:  2 days ago This method formats the value of the least granular unit in the NSDateComponents object, and doesn’t provide a compound format of the date component. important: This method only supports year, month, week of month, day, hour, minute, and second components. The formatter ignores all other date components.

## See Also

### Converting Dates to Formatted Strings

- [localizedString(for:relativeTo:)](foundation/relativedatetimeformatter/localizedstring(for:relativeto:).md)
- [localizedString(fromTimeInterval:)](foundation/relativedatetimeformatter/localizedstring(fromtimeinterval:).md)
- [string(for:)](foundation/relativedatetimeformatter/string(for:).md)
