Swift Dateを表示文字列に変換、ロケール考慮
full
let dateFormatter = DateFormatter() dateFormatter.dateStyle = .full dateFormatter.timeStyle = .full dateFormatter.locale = .current let dateString = dateFormatter.string(from: date)
2021年6月5日 土曜日 15時43分26秒 日本標準時
long
let dateFormatter = DateFormatter() dateFormatter.dateStyle = .long dateFormatter.timeStyle = .long dateFormatter.locale = .current let dateString = dateFormatter.string(from: date)
2021年6月5日 15:43:26 JST
medium
let dateFormatter = DateFormatter() dateFormatter.dateStyle = .medium dateFormatter.timeStyle = .medium dateFormatter.locale = .current let dateString = dateFormatter.string(from: date)
2021/06/05 15:43:26
short
let dateFormatter = DateFormatter() dateFormatter.dateStyle = .short dateFormatter.timeStyle = .short dateFormatter.locale = .current let dateString = dateFormatter.string(from: date)
2021/06/05 15:43