NSDate
1.NSDate对象用来表示一个具体的时间点。
2.NSDate是一个类簇,我们使用的NSDate对象都是它的私有子类的实体。
3.NSDate存储的是GMT时间,使用的时候会根据 当前应用 指定的 时区 进行时间上的增减,以供计算或显示。
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; NSDate *now; NSDateComponents *comps = [[NSDateComponents alloc] init]; NSInteger unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSWeekdayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit; now=[NSDate date]; comps = [calendar components:unitFlags fromDate:now]; NSInteger year = [comps year]; NSInteger month = [comps month]; NSInteger day = [comps day]; NSInteger hour = [comps hour]; NSInteger min = [comps minute]; NSInteger sec = [comps second]; NSLog(@"year:%ld \n \ month:%ld \n \ day:%ld \n \ hour:%ld \n \ min:%ld \n \ sec:%ld", year, month, day, hour, min, sec); //组装 NSString *stringDate = [NSString stringWithFormat:@"%ld%ld%ld%ld%ld%ld", year, month, day, hour, min, sec ]; NSLog(@"stringDate:%@", stringDate);
获取若干天前的日期:
NSTimeInterval secondsPerDay = 24 * 60 * 60;
for (int i = 0; i < 400; i++) {
NSDate *date = [[NSDate alloc] initWithTimeIntervalSinceNow:-i*secondsPerDay];
NSLog(@"%@", date);
}
附件:http://down.51cto.com/data/2363334另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。