Skip to content

Instantly share code, notes, and snippets.

@between40and2
Created November 16, 2022 11:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save between40and2/0f8398c14d4430e1c9bfd8c2bfc3ee20 to your computer and use it in GitHub Desktop.
Save between40and2/0f8398c14d4430e1c9bfd8c2bfc3ee20 to your computer and use it in GitHub Desktop.
WWDC 2021 What's New in Foundation
func parsingDates() {
let date = Date.now
let format = Date.FormatStyle().year().day().month()
let formatted = date.formatted(format) // "Jun 7, 2021"
if let date = try? Date(formatted, strategy: format) {
// example: 2021-06-07 07:00:00 +0000
print(date)
}
}
parsingDates()
func parsingDatesStrategies() {
let strategy = Date.ParseStrategy(
format: "\(year: .defaultDigits)-\(month: .twoDigits)-\(day: .twoDigits)",
timeZone: TimeZone.current)
if let date = try? Date("2021-06-07", strategy: strategy) {
// date is 2021-06-07 07:00:00 +0000
print(date)
}
}
parsingDatesStrategies()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment