0Pricing
Swift Academy · Lesson

Formatting Dates

Display dates with the modern formatting API.

Formatting Dates

Raw Date values are not human-readable. Swift's modern FormatStyle API turns them into localized strings cleanly.

The formatted() Method

Calling .formatted() on a date gives a sensible default string for the user's locale.

import Foundation

let now = Date()
let text = now.formatted()
print("Produced a string: \(!text.isEmpty)")

All lessons in this course

  1. The Date Type and Time Intervals
  2. Calendar and DateComponents
  3. Formatting Dates
  4. Time Zones and Locales
← Back to Swift Academy