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

  • 相关阅读:
    php使用cookie来保存用户登录信息
    Linux下进程操作
    TortoiseSVN无法编辑日志信息的解决方法
    用DIV布局制作公告板
    HashMap的遍历
    实现文本滚动
    子DIV块中设置margintop时影响父DIV块位置的解决办法
    php使用session来保存用户登录信息
    javascript jquery ajax动态提交多个参数 api测试 拂晓风起
    javascript 处理返回json中的\u中文乱码问题(也不是乱码了,就是\u编码) 拂晓风起
  • 原文地址:https://www.cnblogs.com/linxiu-0925/p/5086246.html
Copyright © 2011-2022 走看看