How to get NSDate day, month and year in integer format?

前端 未结 9 1099
长情又很酷
长情又很酷 2020-12-07 15:31

I want to get the day, month and year components of NSDate in integer form i.e. if the date is 1/2/1988 then I should get 1, 2 and 1988 separately as an integer

9条回答
  •  我在风中等你
    2020-12-07 15:57

    U can try this .......

    Mycal = [NSCalendar currentCalendar];
    today = [NSDate date];
    compA =[Mycal components:(NSMonthCalendarUnit | NSDayCalendarUnit | NSYearCalendarUnit | NSWeekdayCalendarUnit) fromDate:today];     
    FirstDateofMonth=[today dateByAddingTimeInterval:([compA day]-1)*(-24*60*60)];
    
    compA =[Mycal components:(NSMonthCalendarUnit | NSDayCalendarUnit | NSYearCalendarUnit | NSWeekdayCalendarUnit) fromDate:FirstDateofMonth];
    today = FirstDateofMonth;
    compA = [Mycal components:(NSMonthCalendarUnit | NSDayCalendarUnit | NSYearCalendarUnit | NSWeekdayCalendarUnit) fromDate:today];
    [compA setMonth:([compA month])];
    [self DrawMonthInPortraitView];
    [compA retain];
    

提交回复
热议问题