我有一个如下所示的函数,它根据小时执行一个函数。如何修改它以便在WEEK的那一天执行?
let date = NSDate()
let calendar = NSCalendar.currentCalendar()
let components = calendar.components(.CalendarUnitHour, fromDate: date)
let hour = components.hour
if(hour >= 9 && hour <= 17)
{
//set your image 'open image'
println("Open")
}
else{
//set your image 'close image'
println("closed")
}
答案 0 :(得分:0)
NSCalendarUnit
可以使用UInt
初始化,因此这为您提供了所有可能的组件:
var flags = NSCalendarUnit(UInt.max)
let components = calendar.components(flags, fromDate: date)
let day=components.day
let hour = components.hour