how to split strings in objective c

前端 未结 4 1576
不知归路
不知归路 2020-12-17 19:32

How to split a string in objective-C? I am working on an short application that contains a date picker. I do display date get it from date picker and display it through a la

4条回答
  •  情深已故
    2020-12-17 20:15

    You can use following code to split the date into separate components:

    NSDate *inputDate = [NSDate date];  //assign the value selected from date picker 
    NSCalendar* calendar = [NSCalendar currentCalendar];
    
    unsigned unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit |  NSDayCalendarUnit;
    NSDateComponents* componentObj = [calendar components:unitFlags fromDate:inputDate];
    NSInteger day = componentObj.day;
    NSInteger month = componentObj.month;
    NSInteger year = componentObj.year;
    

提交回复
热议问题