zoukankan      html  css  js  c++  java
  • 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秒

    };

  • 相关阅读:
    cmake使用总结
    Fatal error RC1015: cannot open include file "xxxx.h" vs2008
    可重入函数(转)
    《左耳听风》-ARTS-打卡记录-第十二周
    异常声明
    QString与const char *相互转换
    Qt中使用子线程去关闭弹出框
    什么是反向代理
    【GOJ 3002】颜色
    【GOJ 2296】毛毛虫
  • 原文地址:https://www.cnblogs.com/wukun168/p/6010818.html
Copyright © 2011-2022 走看看