taiyang2014

在日期选择轮中选择的时间转换成年龄

if (sender.tag == TAG_BUTTON_SUMMIT) {
        NSTimeInterval dateDiff = [[dataPicker date] timeIntervalSinceNow];
        int age= fabs(trunc(dateDiff / (60 * 60 * 24)) / 365);
        ageLabel.text = [NSString stringWithFormat:@"%d", age];
        NSDate *date = [dataPicker date];
        //    限定格式
        NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
        [formatter setDateFormat:@"yyyyMMdd"];
        [formatter setTimeZone:[NSTimeZone timeZoneWithName:@"GMT"]];
       
        NSString *strDate = [formatter stringFromDate:date];
        NSLog(@"$$$$$$$$$$$$$$$$$$$$$$$$$$$%@", strDate);
       
        [_userDic setObject:strDate forKey:USERAGE];
        NSDictionary *user = [NSDictionary dictionaryWithDictionary:_userDic];
        [_dataHandle saveLocalData:USERINFO value:user];
    }

posted on 2015-09-30 17:31  taiyang2014  阅读(286)  评论(0编辑  收藏  举报

导航