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);
            }
           
            
        }

  • 相关阅读:
    考研路线及北大光华学院MBA的一些知识
    返回下表中所有同学语文成绩最低的1次考试成绩, pandas系列
    elasticsearch ES使用文档
    flask 基础用法(自己看的笔记)
    pigx集成sharding jdbc
    从rtmp拉流后进行python鼻子定位demo
    物流-门店监控-在线直播系统搭建-nginx核心部分
    Java中的锁分类与使用
    数据库中的锁
    【转】常见的性能测试缺陷
  • 原文地址:https://www.cnblogs.com/linxiu-0925/p/5086246.html
Copyright © 2011-2022 走看看