IOS获取当前的系统时间的三种方式
来源:互联网 发布:linux修改机器时间 编辑:程序博客网 时间:2024/05/17 16:11
近段业余时间,本人总结了IOS的获取系统时间的三种方式,各有优劣,可以根据实际应用来选择。
//获取当前的系统时间年-月-日 小时-分钟-秒
//方法一
time_t now;
time(&now);
NSDate *_dateline = [NSDate dateWithTimeIntervalSince1970:now];
NSDateFormatter *dateformat=[[NSDateFormatter alloc] init];
[dateformat setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSString * new = [dateformat stringFromDate:_dateline];
NSLog(@"now time = %@",new);
//方法二
NSDate *newDate = [NSDate date];
NSDateFormatter *dateformat=[[NSDateFormatteralloc] init];
[dateformat setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSString * newDateOne = [dateformat stringFromDate:newDate];
[dateformat setFormatterBehavior:NSDateFormatterFullStyle];
[dateformat setTimeZone:[NSTimeZonetimeZoneWithAbbreviation:@"UTC"]];
NSLog(@"%@",newDateOne);
//方法三
NSDate *date = [NSDate date];
NSTimeZone *zone = [NSTimeZonesystemTimeZone];
NSInteger interval = [zone secondsFromGMTForDate: date];
NSDate *localeDate = [date dateByAddingTimeInterval: interval];
NSLog(@"%@", localeDate);
- IOS获取当前的系统时间的三种方式
- JAVA获取当前系统时间的方式
- C语言获取当前系统时间的几种方式
- C语言获取当前系统时间的几种方式
- C语言获取当前系统时间的几种方式
- MFC获取系统当前时间三种方式
- Android 获取系统时间的三种方式
- ios获取当前的时间
- 获取系统当前的时间
- 获取当前系统的时间
- java获得系统当前时间三种方式及日期格式之间的相互转化
- ios 获取系统当前时间
- ios 获取当前系统时间
- iOS获取系统当前时间
- iOS 获取系统当前时间
- iOS 获取系统当前时间
- iOS 获取系统当前时间
- java获取当前系统时间(最好的方式是取当前系统时间的毫秒数)
- ffmpeg与x264编码指南
- ffmpeg x264解码在线视频时常见错误
- LeetCode(24)Swap Nodes in Pairs
- 递归实现汉诺塔问题
- JSF, MyFaces, RichFaces 和 Facelets的区别
- IOS获取当前的系统时间的三种方式
- select选择框控件-jquery.editable-select
- 最简单的WINSOCK通讯模型
- 侥幸过关,还有1年
- Jackson Streaming API To Read And Write JSON
- The install progress of bochs 2.4.6
- [RBP] RaspberryPi系列之四:RBP as a streaming server(一)
- KEIL编译错误信息表
- Hadoop 2 + HBase 0.94 相关资料