NSString 转换 NSdate

    NSString *myDateString = @"2010-12-08";
    //拿到原先的日期格式
    NSDateFormatter *inputFormat = [[NSDateFormatter alloc] init];
    [inputFormat setDateFormat:@"yyyy-MM-dd"]; //2010-12-08 06:53:43
   
    //将NSString转换为NSDate
    NSDate *theDate  = [inputFormat dateFromString:myDateString];

 

    //前一天
    theDate = [[NSDate alloc] initWithTimeInterval:-24*3600 sinceDate:theDate];


  //后一天
    theDate = [[NSDate alloc] initWithTimeInterval:24*3600 sinceDate:theDate];    //设置新的日期格式


    NSDateFormatter *outputFormat = [[NSDateFormatter alloc] init];
    [outputFormat setDateFormat:@"yyyy-MM-dd"];
   
    //将NSDate转换为NSString
    NSString *myNewDateString = [outputFormat stringFromDate:theDate];//2010-12-08 06:53:43 GMT
   
    NSLog(@"%@",myNewDateString);

你可能感兴趣的:(360,2010)