Skip to content

Instantly share code, notes, and snippets.

@dialektike
Created December 7, 2015 14:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dialektike/cb53a70ab4f47c53b1c3 to your computer and use it in GitHub Desktop.
Save dialektike/cb53a70ab4f47c53b1c3 to your computer and use it in GitHub Desktop.
// 아래 코드는 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에 넣습니다.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment