How do I format relative dates and times?

Formatting relative dates and times in Swift can be easily achieved using the `DateFormatter` and `RelativeDateTimeFormatter` classes. The `RelativeDateTimeFormatter` allows you to express dates relative to the current date, making it useful for displaying user-friendly date and time formats.

Here's an example of how you can format relative dates and times in Swift:

        import Foundation

        let now = Date()
        let formatter = RelativeDateTimeFormatter()
        formatter.unitsStyle = .full

        let yesterday = Calendar.current.date(byAdding: .day, value: -1, to: now)!
        let tomorrow = Calendar.current.date(byAdding: .day, value: 1, to: now)!

        print(formatter.localizedString(for: yesterday, relativeTo: now)) // "yesterday"
        print(formatter.localizedString(for: tomorrow, relativeTo: now)) // "tomorrow"
        

Swift DateFormatter RelativeDateTimeFormatter relative dates time formatting swift programming