NSDateComponents of an NSDate

后端 未结 4 682
广开言路
广开言路 2020-12-17 08:07

How do I get the NSDateComponents of a single NSDate? I don\'t want the components of the difference between 2 dates, just the seconds, minutes, hours, day, month and year o

4条回答
  •  眼角桃花
    2020-12-17 08:50

    in Swift 2.x the components you want are passed like this.

    let gregorianCalendar = NSCalendar(calendarIdentifier: NSCalendarIdentifierGregorian) 
    let weekdayHourMinutes = gregorianCalendar?.components([.Weekday, .Hour, .Minute], fromDate: date)
    

提交回复
热议问题