How to get NSDate day, month and year in integer format?

前端 未结 9 1063
长情又很酷
长情又很酷 2020-12-07 15:31

I want to get the day, month and year components of NSDate in integer form i.e. if the date is 1/2/1988 then I should get 1, 2 and 1988 separately as an integer

9条回答
  •  一整个雨季
    2020-12-07 15:52

    let date = Date()
    let calendar = Calendar.current
    
    let year = calendar.component(.year, from: date)
    let month = calendar.component(.month, from: date)
    let day = calendar.component(.day, from: date)
    print("hours = \(year):\(month):\(day)")
    

提交回复
热议问题