NSDate 时间

      NSDate *date =[NSDate date];

        

        NSLog(@"****%@",date);

        //获取明天此时的时间以当前时间为准 时间间隔单位为 秒(以秒为时间单位计算时间间隔)

        NSDate *tomorrw = [NSDate dateWithTimeIntervalSinceNow:24*60*60];//从现在多少秒之后

        NSLog(@"tomorrw:%@",tomorrw);

        NSTimeInterval tim1970 =[date timeIntervalSince1970];//距1970多少秒

        NSLog(@"%f",tim1970);

        //格式化输出

        NSDateFormatter *dateFormater =[[NSDateFormatter alloc]init];

        [dateFormater setDateFormat:@"yyyy年MM月dd日 HH:mm:ss"];

        NSString *dateString = [dateFormater stringFromDate:date];

        NSLog(@"%@",dateString);

//根据秒数获取时间

   long long time = [[bigDic objectForKey:@"setoff_date"] longLongValue];

             NSDate *confromTimesp = [NSDate dateWithTimeIntervalSince1970:time];

            NSDateFormatter *dateFormater =[[NSDateFormatter alloc]init];

            [dateFormater setDateFormat:@"yyyy-MM-dd"];

              NSString *dateString = [dateFormater stringFromDate:confromTimesp];

            

//获取周几.

- (NSString *)getWeekDayFordate:(long long)data

{

    NSArray *weekday = [NSArray arrayWithObjects: [NSNull null], @"周日", @"周一", @"周二", @"周三", @"周四",@"周五", @"周六", nil];

    

    NSDate *newDate = [NSDate dateWithTimeIntervalSince1970:data];

    NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];

    NSDateComponents *components = [calendar components:NSWeekdayCalendarUnit fromDate:newDate];

    

    NSString *weekStr = [weekday objectAtIndex:components.weekday];

    return weekStr;

}

typedef CF_ENUM(CFIndex, CFDateFormatterStyle) {    // date and time format styles

    kCFDateFormatterNoStyle = 0,       // 无输出

    kCFDateFormatterShortStyle = 1,    // 12-10-29 下午2:52

    kCFDateFormatterMediumStyle = 2,   // 2012-10-29 下午2:51:43

    kCFDateFormatterLongStyle = 3,     // 2012年10月29日 GMT+0800下午2时51分08秒

    kCFDateFormatterFullStyle = 4      // 2012年10月29日星期一 中国标准时间下午2时46分49秒

};

原文地址:https://www.cnblogs.com/wukun168/p/6010818.html