设为首页 加入收藏

TOP

iOS获取当前时间
2014-11-24 02:56:04 来源: 作者: 【 】 浏览:0
Tags:iOS 获取 当前 时间

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


iOS获取当前时间 源代码


具体下载目录在 /2013年资料8月/14日/iOS获取当前时间


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇三星S3F9454 ADC应用源代码 下一篇时钟芯片HT1380 操作源码

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: