Вопрос по ios, iphone – Как я могу получить следующую дату, используя NSDate? [Дубликат]

23

Possible Duplicate:
iOS and finding Tomorrow

Как я могу получить следующую дату, используя NSDate. Пожалуйста, пришлите мне решение.

Error: User Rate Limit Exceeded Oh Danny Boy

Ваш Ответ

5   ответов
2

[[NSUserDefaults standardUserDefaults] setObject:[NSDate date]  forKey:@"Date"];

NSDate *tomorrow = [[NSUserDefaults standardUserDefaults] valueForKey:@"Date"];
NSTimeInterval secondsPerDay = 24 * 60 * 60;    
NSDate *date = [tomorrow addTimeInterval:secondsPerDay]; //Change NSDate *date = [tomorrow addTimeInterval:-secondsPerDay]; for yesterday
tomorrow = date;
[self setDate:tomorrow];
dateTextField.text = [self getDate];        
[[NSUserDefaults standardUserDefaults] setObject:tomorrow  forKey:@"Date"]; 
Error: User Rate Limit Exceeded
31

NSDate *now = [NSDate date];
int daysToAdd = 50;  // or 60 :-)

// set up date components
NSDateComponents *components = [[[NSDateComponents alloc] init] autorelease];
[components setDay:daysToAdd];

// create a calendar
NSCalendar *gregorian = [[[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar] autorelease];

NSDate *newDate2 = [gregorian dateByAddingComponents:components toDate:now options:0];
NSLog(@"Clean: %@", newDate2);
MuchError: User Rate Limit Exceeded
Error: User Rate Limit Exceeded
3

NSString *zajtra = [[NSDate date] dateByAddingTimeInterval:86400];
Error: User Rate Limit Exceeded
Error: User Rate Limit Exceeded- [NSDate dateByAddingTimeInterval:]Error: User Rate Limit ExceededNSString?
Error: User Rate Limit Exceeded
Error: User Rate Limit Exceeded
57

// start by retrieving day, weekday, month and year components for yourDate
    NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
    NSDateComponents *todayComponents = [gregorian components:(NSDayCalendarUnit | NSMonthCalendarUnit | NSYearCalendarUnit) fromDate:yourDate];
    NSInteger theDay = [todayComponents day];
    NSInteger theMonth = [todayComponents month];
    NSInteger theYear = [todayComponents year];

    // now build a NSDate object for yourDate using these components
    NSDateComponents *components = [[NSDateComponents alloc] init];
    [components setDay:theDay]; 
    [components setMonth:theMonth]; 
    [components setYear:theYear];
    NSDate *thisDate = [gregorian dateFromComponents:components];
    [components release];

    // now build a NSDate object for the next day
    NSDateComponents *offsetComponents = [[NSDateComponents alloc] init];
    [offsetComponents setDay:1];
    NSDate *nextDate = [gregorian dateByAddingComponents:offsetComponents toDate:thisDate options:0];
    [offsetComponents release];
    [gregorian release];
Error: User Rate Limit Exceeded
Error: User Rate Limit Exceeded
Error: User Rate Limit Exceeded
Error: User Rate Limit Exceeded
Error: User Rate Limit Exceeded Jai
34
NSDate *tomorrow = [NSDate dateWithTimeInterval:(24*60*60) sinceDate:[NSDate date]];

Error: User Rate Limit Exceeded
Error: User Rate Limit Exceeded
Error: User Rate Limit Exceeded
Error: User Rate Limit Exceeded
Error: User Rate Limit Exceeded

Похожие вопросы