DateFormatter Styles
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
let date = Date() | |
let df = DateFormatter() | |
// FULL STYLE | |
df.dateStyle = DateFormatter.Style.full | |
df.timeStyle = DateFormatter.Style.full | |
print(df.string(from: date)) // Friday, December 10, 2021 at 5:00:41 PM Pacific Standard Time | |
// LONG STYLE | |
df.dateStyle = DateFormatter.Style.long | |
df.timeStyle = DateFormatter.Style.long | |
print(df.string(from: date)) // December 10, 2021 at 5:00:41 PM PST | |
// MEDIUM STYLE | |
df.dateStyle = DateFormatter.Style.medium | |
df.timeStyle = DateFormatter.Style.medium | |
print(df.string(from: date)) // Dec 10, 2021 at 5:01:29 PM | |
// SHORT STYLE | |
df.dateStyle = DateFormatter.Style.short | |
df.timeStyle = DateFormatter.Style.short | |
print(df.string(from: date)) // 12/10/21, 5:00 PM | |
// NONE STYLE | |
df.dateStyle = DateFormatter.Style.none | |
df.timeStyle = DateFormatter.Style.none | |
print(df.string(from: date)) // nothing! :) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment