IOS获取当前时间
2013-08-13 23:50
417 查看
NSDate
1.NSDate对象用来表示一个具体的时间点。
2.NSDate是一个类簇,我们使用的NSDate对象都是它的私有子类的实体。
3.NSDate存储的是GMT时间,使用的时候会根据 当前应用 指定的 时区 进行时间上的增减,以供计算或显示。
获取若干天前的日期:
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
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
相关文章推荐
- iOS获取当前时间和获取明天的日期
- iOS 获取当前时间及时间戳的互换
- iOS 获取当前时间 年、月、日、周几
- ios 获取当前时间,并转换成时间戳
- iOS获取当前时间(当前时区)
- iOS 获取当前时间,并按照要求格式显示
- iOS 本地时间 / UTC时间 / 时间戳等操作 / 获取当前年月日
- IOS笔记:获取当前时间,并转化为一定格式字符串
- iOS 获取当前时间并且显示走在视图上
- iOS 获取当前时间格式化字符串
- ios 获取当前的系统时间 年-月-日 小时-分钟-秒
- iOS 获取系统当前时间
- iOS获取当前时间和当前时间戳的方法
- iOS积累--字符串转化为NSDate, 获取当前时区的系统时间
- iOS 获取系统当前时间
- ios 获取系统当前时间
- 获取当前日期、时间--iOS开发
- iOS获取当前时间
- ios获取当前时间年月日时分秒
- iOS获取当前时间日期,并按规定格式显示【原创】