A colossal Dreamer: GR鐵塔-天生我材

Swift: getting Date Components 본문

Development/아이폰

Swift: getting Date Components

江多林 2022. 7. 18. 11:53

Swift 실행환경에서 날짜 성분 출력하는 예제

 

import Foundation

let now = Date()
let calendar = Calendar.current

print("era:", calendar.component(.era, from: now))
print("year:", calendar.component(.year, from: now))
print("yearForWeekOfYear:", calendar.component(.yearForWeekOfYear, from: now))
print("quarter:", calendar.component(.quarter, from: now))
print("month:", calendar.component(.month, from: now))
print("weekOfYear:", calendar.component(.weekOfYear, from: now))
print("weekOfMonth:", calendar.component(.weekOfMonth, from: now))
print("weekday:", calendar.component(.weekday, from: now))
print("weekdayOrdinal:", calendar.component(.weekdayOrdinal, from: now))
print("day:", calendar.component(.day, from: now))
print("hour:", calendar.component(.hour, from: now))
print("minute:", calendar.component(.minute, from: now))
print("second:", calendar.component(.second, from: now))
print("nanosecond:", calendar.component(.nanosecond, from: now))
print("calendar:", calendar.component(.calendar, from: now))
print("timeZone:", calendar.component(.timeZone, from: now))
더보기

era: 1

year: 2022

yearForWeekOfYear: 2022

quarter: 0 < - 분기 구현안됨. The quarter unit is largely unimplemented, and is not recommended for use.

month: 7

weekOfYear: 30 <- 1년중에 30주차

weekOfMonth: 4 <- 넷째 주 그러나 수요일 기준의 넷째 주 아님에 유의하기

weekday: 2 <- 월요일(2) / 1은 일요일

weekdayOrdinal: 3 <- 바로 위 weekday(월요일) 기준으로 7월의 세 번째 월요일

day: 18

hour: 11

minute: 42

second: 23

nanosecond: 268340945

calendar: 9223372036854775807

timeZone: 9223372036854775807