• iOS获取系统时间


    NSString* date;
    NSDateFormatter* formatter = [[NSDateFormatteralloc]init];
           [formattersetDateFormat:@"YYYY-MM-dd%20hh:mm:ss"];
           date = [formatterstringFromDate:[NSDatedate]];

    date 显示为 2011-11-01%2012:12:12

    想实现查找几天前的时间,可以用这个方法
      NSDate* date = [[NSDate alloc] init];
            date = [date dateByAddingTimeInterval:-5*3600*24];
    这是用现在的时间,往前面减5天,得到的时间。

     

    好简单!简单的很假!

     

     

    获取连续日期:

     NSDate *date = [NSDate date];
        // 2013-04-07 11:14:45
        NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
        // HH是24进制,hh是12进制
        formatter.dateFormat = @"MM.dd";
        
        NSDateFormatter *formatter2 = [[NSDateFormatter alloc] init];
        // HH是24进制,hh是12进制
        formatter2.dateFormat = @"YYYY-MM-dd";
        
        // formatter.locale = [[[NSLocale alloc] initWithLocaleIdentifier:@"zh_CN"] autorelease];
        NSString *string = [formatter stringFromDate:date];
        NSLog(@"%@", string);
        // 返回的格林治时间
        NSMutableArray *dates = [NSMutableArray array];
    //    NSMutableArray *weekDays = [NSMutableArray array];
        NSString * registe = @"3";
        if([registe integerValue]>1)
        {
            for (int i=0; i<[registe integerValue]; i++ ) {
                NSDate *newDate = [[NSDate alloc] initWithTimeIntervalSinceReferenceDate:([date timeIntervalSinceReferenceDate] - 24*3600*i)];
                
                NSString *currentDateStr = [formatter stringFromDate:newDate];
                [dates addObject:currentDateStr];
                   NSLog(@"——————%@",dates);
                
                   }
            for (int i= [registe intValue]; i<7; i++) {
                
                 NSDate *newDate = [[NSDate alloc] initWithTimeIntervalSinceReferenceDate:( [date timeIntervalSinceReferenceDate] +24*3600 *(i- ([registe intValue]-1))*24*3600)];
    //            NSDate *newDate = [[NSDate alloc] initWithTimeIntervalSinceReferenceDate:( [date timeIntervalSinceReferenceDate] +24*3600 *(i-1))];
                
                NSString *currentDateStr = [formatter stringFromDate:newDate];
                [dates addObject:currentDateStr];
                
                NSLog(@"哈哈哈哈%@",dates);
            }
           
            
        }

  • 相关阅读:
    onkeydown事件
    单击循环事件
    for-in循环
    in运算符
    数组成员升序降序排列
    bzoj 3754: Tree之最小方差树 模拟退火+随机三分
    bzoj 3752: Hack 预处理+暴力dfs
    hdu 5269 ZYB loves Xor I 分治 || Trie
    bzoj 4501: 旅行 01分数规划+概率期望dp
    bzoj 4260: REBXOR Trie+乱搞
  • 原文地址:https://www.cnblogs.com/linxiu-0925/p/5086246.html
Copyright © 2020-2023  润新知