swift에서 초 단위의 데이터를 사용하지 않고, 내일 날자를 구하는 코드입니다.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 아래 코드는 swift 2.0에서 현재 시간에 하루를 더하는 것을 보여주고 있습니다. | |
let now = NSDate() // 현재 시간 정보를 넣습니다. | |
let comp = NSDateComponents() // 하루를 더하기 위해서 NSDateComponents를 하나 만듭니다. | |
comp.setValue(1, forKey: "day") // 위에서 만든 곳에 1일을 넣습니다. forKey를 바꾸면 다른 것도 넣을 수 있습니다. | |
let myCal = NSCalendar.init(calendarIdentifier: NSCalendarIdentifierGregorian) // 하루를 더해서 넣을 NSCalendar를 하나 만듭니다. | |
let tomorrow = myCal!.dateByAddingComponents(comp, toDate: now, options: NSCalendarOptions(rawValue: 0)) // 위에서 만든 현재 시간인 now에 myCal을 이용하여 하루를 더해서 tomorrow에 넣습니다. |