Skip to content

Instantly share code, notes, and snippets.

@yycking
Last active August 9, 2022 03:27
Show Gist options
  • Save yycking/8b37985cd9618515459286424b7c438b to your computer and use it in GitHub Desktop.
Save yycking/8b37985cd9618515459286424b7c438b to your computer and use it in GitHub Desktop.
swift TimeZone list like setting
import Cocoa
let formatter = DateFormatter()
formatter.dateStyle = .long
formatter.dateFormat = "(O) VVV"
formatter.locale = Locale(identifier: "zh")
TimeZone.knownTimeZoneIdentifiers
.compactMap(TimeZone.init(identifier:))
.map { timeZone -> String in
formatter.timeZone = timeZone
return formatter.string(from: Date())
}.forEach {
print($0)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment