しめ鯖日記

swift, iPhoneアプリ開発, ruby on rails等のTipsや入門記事書いてます

Swiftで月・火・水…と言った曜日の文字列を取得する

DateFormatter().shortWeekdaySymbolsで取得できます。

print(DateFormatter().shortWeekdaySymbols) // → ["日", "月", "火", "水", "木", "金", "土"]

○曜日という表記はweekdaySymbolsというメソッドで取れます。

print(DateFormatter().weekdaySymbols) // → ["日曜日", "月曜日", "火曜日", "水曜日", "木曜日", "金曜日", "土曜日"]

他にも色々な情報が取れるようです。
紀元前や四半期も取れるのは面白いですね。

print(DateFormatter().monthSymbols) // → ["1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"]
print(DateFormatter().shortMonthSymbols) // → ["1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"]
print(DateFormatter().eraSymbols) // → ["紀元前", "西暦"]
print(DateFormatter().AMSymbol) // → 午前
print(DateFormatter().PMSymbol) // → 午後
print(DateFormatter().longEraSymbols) // → ["紀元前", "西暦"]
print(DateFormatter().veryShortMonthSymbols) // → ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"]
print(DateFormatter().standaloneMonthSymbols) // → ["1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"]
print(DateFormatter().shortStandaloneMonthSymbols) // → ["1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"]
print(DateFormatter().veryShortStandaloneMonthSymbols) // → ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"]
print(DateFormatter().veryShortWeekdaySymbols) // → ["日", "月", "火", "水", "木", "金", "土"]
print(DateFormatter().standaloneWeekdaySymbols) // → ["日曜日", "月曜日", "火曜日", "水曜日", "木曜日", "金曜日", "土曜日"]
print(DateFormatter().shortStandaloneWeekdaySymbols) // → ["日", "月", "火", "水", "木", "金", "土"]
print(DateFormatter().veryShortStandaloneWeekdaySymbols) // → ["日", "月", "火", "水", "木", "金", "土"]
print(DateFormatter().quarterSymbols) // → ["第1四半期", "第2四半期", "第3四半期", "第4四半期"]
print(DateFormatter().shortQuarterSymbols) // → ["Q1", "Q2", "Q3", "Q4"]
print(DateFormatter().standaloneQuarterSymbols) // → ["第1四半期", "第2四半期", "第3四半期", "第4四半期"]
print(DateFormatter().shortStandaloneQuarterSymbols) // → ["Q1", "Q2", "Q3", "Q4"]