Adding a day to current date in iOS

前端 未结 6 1679
孤城傲影
孤城傲影 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 12:02

    First Thing,you are assigning day instead of month to NSDateComponent. Execute following code and find difference between inDate And newDate

    NSCalendar *calendar = [NSCalendar currentCalendar];
    NSDateComponents *components = [calendar components:NSCalendarUnitMonth fromDate:inDate];
    

    NSInteger monthFlag = 1; components.month = minuteFlag;

    // Retrieve date with increased days count
    NSDate *newDate = [[NSCalendar currentCalendar]
                       dateByAddingComponents:components
                                       toDate:monthFlag
                                      options:0];
    

提交回复
热议问题