Adding a day to current date in iOS

前端 未结 6 1682
孤城傲影
孤城傲影 2021-01-02 11:03

I saw this post: iOS and finding Tomorrow.

The code provided is:

units = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit;
NSDateComponen         


        
6条回答
  •  盖世英雄少女心
    2021-01-02 11:52

    Form a date component with number of days you want to add to your original date. From the current calendar form the date by adding the this component to your original date.

    NSDateComponents *dateComponents = [NSDateComponents new];
    dateComponents.day = 1;
    NSDate *newDate = [[NSCalendar currentCalendar]dateByAddingComponents:dateComponents 
                                                                   toDate: selectedDate 
                                                                  options:0];
    

提交回复
热议问题