Get first day in a month from NSCalendar

前端 未结 6 1376
醉话见心
醉话见心 2021-01-12 05:24

I have this subset of a method that needs to get day one of the current month.

NSDate *today = [NSDate date];  // returns correctly 28 february 2013
NSCalend         


        
6条回答
  •  旧时难觅i
    2021-01-12 05:37

    Easy way of getting to the 1st from a given date:

    NSDate *first = [gregorian dateBySettingUnit:NSCalendarUnitDay value:1 ofDate:date options:0]; 
    

提交回复
热议问题