import UIKit
let components = NSDateComponents()
components.setValue(1, forComponent: NSCalendarUnit.CalendarUnitDay)
components.setValue(1, forComponent: NSCalendarUnit.CalendarUnitMonth)
components.setValue(2014, forComponent: NSCalendarUnit.CalendarUnitYear)
println(components.weekday) // 9223372036854775807
任何人都有任何想法,为什么我得到9223372036854775807
而不是1-7的值?
答案 0 :(得分:3)
let dateStyler = NSDateFormatter()
dateStyler.dateFormat = "yyyy-MM-dd"
let myDate = dateStyler.dateFromString("2014-01-01")!
let myWeekday = NSCalendar.currentCalendar().components(NSCalendarUnit.CalendarUnitWeekday, fromDate: myDate).weekday