zoukankan      html  css  js  c++  java
  • NSDate

        NSDate *date = [NSDate date];
        date = [NSDate dateWithTimeIntervalSinceNow:10];//返回当前时间10秒后的时间,
        date = [NSDate dateWithTimeIntervalSince1970:10];//返回1970-1-1 00:00:00时间10秒后的时间
        NSTimeInterval interval = [date timeIntervalSince1970];//返回1970-1-1开始走过的毫秒数
        
        
        // 跟其他时间进行对比
        NSDate *date2 = [NSDate date];
        // 返回比较早的那个时间
        [date earlierDate:date2];
        // 返回比较晚的那个时间  
        [date laterDate:date2];
        //获取两个时间的时间差
        [date timeIntervalSinceDate: date2];
        
        
        /**
         *  例:
         */
        NSDate *date3 = [NSDate date];
        // 2013-04-07 11:14:45
        NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
        // HH是24进制,hh是12进制
        formatter.dateFormat = @"yyyy-MM-dd HH:mm:ss";
        // formatter.locale = [[[NSLocale alloc] initWithLocaleIdentifier:@"zh_CN"] autorelease];
        NSString *string = [formatter stringFromDate:date3];
        NSLog(@"%@", string);
        // 返回的格林治时间
        NSDate *date4 = [formatter dateFromString:@"2010-09-09 13:14:56"];

     

  • 相关阅读:
    CentOS 7 安装MySQL 5.7
    Introduction to BGP (4)
    Introduction to BGP (3)
    Introduction to BGP (2)
    Introduction to BGP (1)
    Cisco NAT Fundation
    Linux安装Nginx
    GRE协议学习与练习
    Oracle Study Note : Users and Basic Security
    Oracle Study Note : Tablespace and Data Files
  • 原文地址:https://www.cnblogs.com/pengyunjing/p/5922826.html
Copyright © 2011-2022 走看看