有一个需求获取当天的0点 做分界线, 然后去获取步数的数据的, 发现都是oc的,
就转了下swift版本的
`
extension NSDate{
/// 当前的0 点 0分 0 秒时间
var currentDayzeroOfDate:NSDate{
let calendar:NSCalendar = NSCalendar.currentCalendar()
//calendar.components(NSCalendarUnit(), fromDate: self)//UIntMax
let unitFlags: NSCalendarUnit = [
NSCalendarUnit.Year,
NSCalendarUnit.Month,
NSCalendarUnit.Day,
.Hour,
.Minute,
.Second ]
//calendar.components(unitFlags, fromDate: self)//解析当前的时间 返回NSDateComponents 解析后的数据后面设置解析后的时间在反转
let components = calendar.components(unitFlags, fromDate: self)//NSDateComponents() 不初始化, 直接返回解析的时间
components.hour = 0
components.minute = 0
components.second = 0
print(" 2 \(components.year) \(components.month) \(components.day) \( components.hour)")
let date = calendar.dateFromComponents(components)
return date!
}
}
`