OC中data与date

来源:互联网 发布:淘宝天猫8折代购原理 编辑:程序博客网 时间:2024/06/05 18:08

今天老师讲了data,data它用来设置缓冲区、将文件的内容读入缓冲区,或将缓冲区的内容写到一个文件。

这个缓冲区也是有可变(NSData)和不可变(NSMutableDate)之分的 



日期与时间

NSDate

初始化一个data

 NSDate *date1 = [NSDatedate];

       NSLog(@"%@",date1);


//日期比较,1.两个日期的时间戳

     NSTimeInterval timeIntervalSince1970  = [[NSDatedate] timeIntervalSince1970];

        

       NSLog(@"%f",timeIntervalSince1970);

        

       //

     NSTimeInterval timeIntervalSinceNow = [[NSDatedate ] timeIntervalSinceNow];

       NSLog(@"%f",timeIntervalSinceNow);

        

        

        

       NSDate  *dateNow = [NSDatedate];

        






NSCalendar创建一个时间很方便


//如何日期转成字符串

        NSDateFormatter *matter =  [NSDateFormatternew];

        

       //设置时区

        matter.timeZone = [NSTimeZonedefaultTimeZone];

        //设置时间输出格式

        [matter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];

        [matter setDateFormat:@"yyyyMMdd HHmmss"];

        

       NSString *string1 = [matter stringFromDate:[NSDate  date]];

        

       NSLog(@"%@",string1);

        

      

        

        //将字符串转化成日期

        NSString *string2 =@"1970-01-01 08:00:00";

        

        [matter setTimeZone:[NSTimeZonetimeZoneWithAbbreviation:@"UFC"]];

        

        [matter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];

        

       NSDate *date9 =  [matter dateFromString:string2];

        

       NSLog(@"%@",date9);

        

        NSTimeInterval timeInterval = date9.timeIntervalSinceNow;

        

       NSLog(@"%f",-timeInterval);

       int m = (int)-timeInterval/60;

       NSLog(@"%d",m);

        

        

        NSTimeInterval timeInterval2 =   [[NSDatedate] timeIntervalSince1970];

        

       NSLog(@"%f",timeInterval2);

        



0 0
原创粉丝点击