计时
//时间
let timeIndex = model.expireDatetime?.endIndex.advancedBy(-cutLength)
let timeStr = model.expireDatetime?.substringToIndex(timeIndex!)
//转换成日期
let df = NSDateFormatter()
df.dateFormat = "yyyy-MM-dd HH:mm:ss"
let expireDate = df.dateFromString(timeStr!)
//日历对象
let calendar = NSCalendar.currentCalendar()
/*
第一个参数:需要计算年月日时分秒里面的哪一项
第二个参数:开始时间
第三个参数:结束时间
第四个参数:选项
*/
let unitFlags = NSCalendarUnit(rawValue: NSCalendarUnit.Hour.rawValue | NSCalendarUnit.Minute.rawValue |
NSCalendarUnit.Second.rawValue
)
let dateComponents = calendar.components(unitFlags, fromDate: NSDate(), toDate: expireDate!, options: NSCalendarOptions(rawValue: 0))
self.timeLabel.text = String(format: "剩余%02d:%02d:%02d", dateComponents.hour, dateComponents.minute, dateComponents.second)
//原价
let priceStr = "¥:\(model.lastPrice!)"
self.lastPriceLabel.text = priceStr
横线
if self.lineView == nil {
let lineView = UIView(frame: CGRectMake(0,10,60,1))
lineView.backgroundColor = UIColor.blackColor()
self.lineView = lineView
self.lastPriceLabel.addSubview(self.lineView!)
}