LoginSignup
5
5

More than 5 years have passed since last update.

Swift で月の最初の日を得る

Last updated at Posted at 2015-08-30

メモ

NSDate, NSCalendar, NSCalendarComponents を使って月の最初の日を得る

var date = NSDate()
var calendar = NSCalendar.currentCalendar()
var comps = calendar.components(NSCalendarUnit.CalendarUnitDay, fromDate: date)
comps.day = comps.day - comps.day - comps.day + 1
let firstDay = calendar.dateByAddingComponents(comps, toDate: NSDate(), options: nil)
println(firstDay)

出力結果
Optional(2015-08-01 10:34:05 +0000)

5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5