<!--
{
  "availability" : [
    "iOS: 15.0.0 -",
    "iPadOS: 15.0.0 -",
    "macCatalyst: 15.0.0 -",
    "macOS: 12.0.0 -",
    "tvOS: 15.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 8.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/Date/formatted(date:time:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "s:10Foundation4DateV9formatted4date4timeSSAC11FormatStyleV0bG0V_AH04TimeG0VtF"
  },
  "title" : "formatted(date:time:)"
}
-->

# formatted(date:time:)

Generates a locale-aware string representation of a date using specified date and time format styles.

```
func formatted(date: Date.FormatStyle.DateStyle, time: Date.FormatStyle.TimeStyle) -> String
```

## Parameters

`date`

The date format style to apply to the date.

`time`

The time format style to apply to the date.

## Return Value

A string, formatted according to the specified date and time styles.

## Discussion

When displaying a date to a user, use the convenient [`formatted(date:time:)`](/documentation/Foundation/Date/formatted(date:time:)) instance method to customize the string representation of the date. Set the date and time styles of the date format style separately, according to your particular needs.

For example, to create a string with a full date and no time representation, set the [`Date.FormatStyle.DateStyle`](/documentation/Foundation/Date/FormatStyle/DateStyle) to [`complete`](/documentation/Foundation/Date/FormatStyle/DateStyle/complete) and the [`Date.FormatStyle.TimeStyle`](/documentation/Foundation/Date/FormatStyle/TimeStyle) to [`omitted`](/documentation/Foundation/Date/FormatStyle/TimeStyle/omitted). Conversely, to create a string representing only the time, set the date style to [`omitted`](/documentation/Foundation/Date/FormatStyle/DateStyle/omitted) and the time style to [`complete`](/documentation/Foundation/Date/FormatStyle/TimeStyle/complete).

```swift
let birthday = Date()

birthday.formatted(date: .complete, time: .omitted) // Sunday, January 17, 2021
birthday.formatted(date: .omitted, time: .complete) // 4:03:12 PM CST
```

You can create string representations of a [`Date`](/documentation/Foundation/Date) instance with several levels of brevity using a variety of preset date and time styles. This example shows date styles of [`long`](/documentation/Foundation/Date/FormatStyle/DateStyle/long), [`abbreviated`](/documentation/Foundation/Date/FormatStyle/DateStyle/abbreviated), and [`numeric`](/documentation/Foundation/Date/FormatStyle/DateStyle/numeric), and time styles of [`shortened`](/documentation/Foundation/Date/FormatStyle/TimeStyle/shortened), [`standard`](/documentation/Foundation/Date/FormatStyle/TimeStyle/standard), and [`complete`](/documentation/Foundation/Date/FormatStyle/TimeStyle/complete).

```swift
let birthday = Date()

birthday.formatted(date: .long, time: .shortened) // January 17, 2021, 4:03 PM
birthday.formatted(date: .abbreviated, time: .standard) // Jan 17, 2021, 4:03:12 PM
birthday.formatted(date: .numeric, time: .complete) // 1/17/2021, 4:03:12 PM CST

birthday.formatted() // Jan 17, 2021, 4:03 PM
```

The default date style is [`abbreviated`](/documentation/Foundation/Date/FormatStyle/DateStyle/abbreviated) and the default time style is [`shortened`](/documentation/Foundation/Date/FormatStyle/TimeStyle/shortened).

For the default date formatting, use the [`formatted()`](/documentation/Foundation/Date/formatted()) method. To customize the formatted measurement string, use the [`formatted(_:)`](/documentation/Foundation/Date/formatted(_:)) method and include a `Date.FormatStyle`.

For more information about formatting dates, see the [`Date.FormatStyle`](/documentation/Foundation/Date/FormatStyle).

---

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)