问题
How can I reduce 5
or 10
minutes from current time and then store it as date format in Swift 2.0 ?
let now = NSDate()
var reducedTime = ???? \\ Here I want 10 minutes reduced from current time.
If current time is 02:20:00, then reducedTime
should be 02:10:00
How can I do this in a simplest way ???
回答1:
You can use calendar method dateByAddingUnit and subtract 10 minutes fro the date.
let now = NSDate()
let reducedTime = NSCalendar(calendarIdentifier: NSCalendarIdentifierGregorian)?.dateByAddingUnit(.Minute, value: -10, toDate: now, options: NSCalendarOptions())
来源:https://stackoverflow.com/questions/33025860/how-to-reduce-few-minutes-for-current-date-in-swift-2-0