Adding days to NSDate

后端 未结 9 1756
广开言路
广开言路 2021-01-02 04:34

I want add days to a date, I got many codes for this but none of them are working for me below shown is my code,please somebody help me to fix this issue

int         


        
相关标签:
9条回答
  • 2021-01-02 05:18
        NSDate *Date=[datePicker date];
    NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
    [dateFormat setDateFormat:@"dd.MM.yy EEEE h:mm a"];
    
    0 讨论(0)
  • 2021-01-02 05:19
    NSDateComponents *offsetComponents = [[NSDateComponents alloc] autorelease];
    [offsetComponents setDay:1];
    
    newDate = [[[CalendarContainer sharedCalendarContainer] gregorian] dateByAddingComponents:offsetComponents toDate:currentlyDisplayedDate options:0];
    
    0 讨论(0)
  • 2021-01-02 05:23

    You can add days to an NSDate by adding a time interval

    NSDate* newDate = [date dateWithTimeInterval:3600*24*numberOfDays sinceDate:otherDate];
    

    Although if you want to be really accurate about it, and take into account leap seconds, day light saving times and all this kind of thing you might want to use NSDateComponents as described in the Date and Time Programming Guide and Omtara's link.

    0 讨论(0)
提交回复
热议问题