Skip to content

Instantly share code, notes, and snippets.

@ole
Created June 18, 2021 19:27
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ole/9a1de9a7c79555c0d96f24803f3b1df6 to your computer and use it in GitHub Desktop.
Save ole/9a1de9a7c79555c0d96f24803f3b1df6 to your computer and use it in GitHub Desktop.
ISO8601 date formatting in Foundation in iOS 15/macOS 12
import Foundation
let date = Date.now
date.formatted(.iso8601) // "20210618T191800Z"
date.formatted(.iso8601.year().month().day().dateSeparator(.dash)) // "2021-06-18"
date.formatted(.iso8601.dateSeparator(.dash).timeSeparator(.colon)) // "2021-06-18T19:18:00Z"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment