获取网络时间
2015-09-21 21:54
519 查看
- (NSDate *)getInternetDate { NSString *urlString = @"http://m.baidu.com"; urlString = [urlString stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding]; // 实例化NSMutableURLRequest,并进行参数配置 NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init]; [request setURL:[NSURL URLWithString: urlString]]; [request setCachePolicy:NSURLRequestReloadIgnoringCacheData]; [request setTimeoutInterval: 2]; [request setHTTPShouldHandleCookies:FALSE]; [request setHTTPMethod:@"GET"]; NSHTTPURLResponse *response; [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:nil]; // 处理返回的数据 // NSString *strReturn = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding]; NSLog(@"response is %@",response); NSString *date = [[response allHeaderFields] objectForKey:@"Date"]; date = [date substringFromIndex:5]; date = [date substringToIndex:[date length]-4]; NSDateFormatter *dMatter = [[NSDateFormatter alloc] init]; dMatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]; [dMatter setDateFormat:@"dd MMM yyyy HH:mm:ss"]; NSDate *netDate = [[dMatter dateFromString:date] dateByAddingTimeInterval:60*60*8]; return netDate; }
相关文章推荐
- AFNetworking https自签名证书 -1012 解决方案
- Xcode7 网络请求报错:The resource could not be loaded because
- BP神经网络及matlab实现
- 《计算机网络》总结
- 2015北京赛区网络赛 Boxes
- /etc/profile和 . profile 文件 http://blog.csdn.net/louiswang2009/article/details/5886575
- hdu5461(2015沈阳网络赛L题)
- main函数调用、进程终止以及命令行参数和环境表http://www.tuicool.com/articles/FNnMNr
- UNIX环境编程学习笔记(16)——进程管理之进程环境变量 http://www.cnblogs.com/lienhua34/p/4005367.html
- hdu5452(2015沈阳网络赛C题)
- hdu5455(2015沈阳网络赛F题)
- hdu5459(2015沈阳网络赛J题)
- 农村借贷会是网络巨头的下一个角斗场吗?
- TCP客户/服务器程序示例
- iOS9 HTTP 不能正常使用的解决办法
- 常见的HTTP状态码
- Android请求网络共通类——Hi_博客 Android App 开发笔记
- centos 7 网络配置( 网关、dns、ip地址配置)
- ACM-ICPC国际大学生程序设计竞赛北京赛区(2015)网络赛 B Mission Impossible 6
- Linux环境变量的设置和查看方法 http://soft.chinabyte.com/os/169/11412169.shtml