//获取当前年月日和星期
NSArray * arrWeek=[NSArray arrayWithObjects:@"星期日",@"星期一",@"星期二",@"星期三",@"星期四",@"星期五",@"星期六", nil];
NSDate *date = [NSDate date];
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
NSInteger unitFlags = NSCalendarUnitYear |
NSCalendarUnitMonth |
NSCalendarUnitDay |
NSCalendarUnitWeekday |
NSCalendarUnitHour |
NSCalendarUnitMinute |
NSCalendarUnitSecond;
NSDateComponents *comps = [calendar components:unitFlags fromDate:date];
NSInteger week = [comps weekday];
NSInteger year=[comps year];
NSInteger month = [comps month];
NSInteger day = [comps day];
NSString *dataStr = [NSString stringWithFormat:@"%ld年%ld月%ld日(%@)",(long)year,(long)month,(long)day,arrWeek[week-1]];
//获取下个月的今天的Date
NSDate *currentDate = [NSDate date];//获取当前时间,日期
NSCalendar *calendarnow = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
NSDateComponents *comps = [[NSDateComponents alloc] init];
NSInteger unitFlags = NSCalendarUnitYear |
NSCalendarUnitMonth |
NSCalendarUnitDay;
comps = [calendarnow components:unitFlags fromDate:currentDate];
NSDateComponents *adcomps = [[NSDateComponents alloc] init];
[adcomps setYear:0];
[adcomps setMonth:+1];
[adcomps setDay:0];
NSDate *newdate = [calendarnow dateByAddingComponents:adcomps toDate:currentDate options:0];
//获取年月日
NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
[formatter setDateFormat:@"yyyy"];//设置显示的日期
NSString *currentyearString = [NSString stringWithFormat:@"%@",[formatter stringFromDate:currentDate]];
// Get Current Month
[formatter setDateFormat:@"MM"];
NSString *currentMonthString = [NSString stringWithFormat:@"%@",[formatter stringFromDate:currentDate]];
//求两个时间的间隔
NSInteger second = [strDate timeIntervalSinceDate:currentDate];
原文:http://www.cnblogs.com/lizongkai/p/5161345.html