iOS中获取系统时间
2015-10-14 08:36
369 查看
// 获取系统当前时间
NSDate * date = [NSDate date]; NSTimeInterval sec = [date timeIntervalSinceNow]; NSDate * currentDate = [[NSDate alloc] initWithTimeIntervalSinceNow:sec]; //设置时间输出格式: NSDateFormatter * df = [[NSDateFormatter alloc] init ]; [df setDateFormat:@"yyyy年MM月dd日 HH小时mm分ss秒"]; NSString * na = [df stringFromDate:currentDate]; NSLog(@"系统当前时间为:%@",na);
//获得系统日期 NSCalendar * cal=[NSCalendar currentCalendar]; NSUInteger unitFlags=NSDayCalendarUnit|NSMonthCalendarUnit|NSYearCalendarUnit; NSDateComponents * conponent= [cal components:unitFlags fromDate:senddate]; NSInteger year=[conponent year]; NSInteger month=[conponent month]; NSInteger day=[conponent day]; NSString * nsDateString= [NSString stringWithFormat:@"%4d年%2d月%2d日",year,month,day];
NSLog(@"系统当前日期为:%@",nsDateString);
相关文章推荐
- 蓝懿 iOs 刘国斌 iOS
- iOS多态特性
- iOS简介
- IOS(Simulator)模拟器切换横竖屏的快捷键
- iOS 苹果官方Demo合集
- iOS 推送消息的原理
- iOS-MJExtension框架使用总结
- iOS-APP后台运行代码
- iOS项目中常用的第三方开源库
- iOS-自定义cell步骤总结
- iOS-NSDate (Extension)
- iOS控制台打印NSLog增强版
- iOS 内存中的ViewController释放
- iOS支付
- iOS 键盘回收实现步骤
- iOS开发常用的第三方类库
- IOS中打开应用实现检查更新的功能
- ios9+xcode7 适配笔记
- iOS单例设计模式
- IOS请求H5页面、要求自定义agent判断是电脑、安卓还是iPhone登录