方法一:从url的response的header中提取

- (void)viewDidLoad
{[super viewDidLoad];// Do any additional setup after loading the view, typically from a nib.NSURL *url=[NSURL URLWithString:@"http://www.baidu.com"];NSURLRequest *request=[NSURLRequest requestWithURL:url];NSURLConnection *connection=[[NSURLConnection alloc]initWithRequest:request delegate:self startImmediately:YES];[connection start];
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{  NSLog(@"response%@",response);  NSHTTPURLResponse *httpResponse=(NSHTTPURLResponse *)response;  if ([response respondsToSelector:@selector(allHeaderFields)]) {  NSDictionary *dic=[httpResponse allHeaderFields];  NSLog(@"dic:%@",dic);  NSString *time=[dic objectForKey:@"Date"];  NSString *time1=[time substringFromIndex:16];  NSString *time2=[time1 substringToIndex:9];  NSArray*array=[time2 componentsSeparatedByString:@":"];  int hour=[[array objectAtIndex:0] intValue];  int minute=[[array objectAtIndex:1] intValue];  NSString *now=[NSString stringWithFormat:@"%0.2d:%0.2d",hour+8,minute];  NSLog(@"date:%@",now);  }
}  

方法二:从下面的字段中提取

NSStringEncoding chineseEnc = CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000);
NSString *webString=[NSString stringWithContentsOfURL:[NSURL URLWithString:@"http://www.time.ac.cn/timeflash.asp?user=flash"] encoding:chineseEnc error:nil];NSLog(@"%@",webString);
webString====<?xml version='1.0' encoding='GB2312'?><ntsc><time><year>2013</year><month>12</month><day>18</day><Weekday></Weekday><hour>12</hour><minite>0</minite><second>12</second><Millisecond></Millisecond></time></ntsc>
从webString(xml文件格式)里面提取出时间就是了

通过NSURL获取网络标准时间相关推荐

  1. 获取网络时间(国家标准时间-北京时间为准)

    获取网络时间,有些网站有偏差,提供几个比较靠谱的网站: /**  * 读取网络时间  *  */ public class NetworkTime { public static void main( ...

  2. iOS 获取网络时间

    iOS 获取网络时间 也许你会因为当前手机时间不准确而导致自己的程序在使用时间上出现一些问题,那么下面这块代码也许会帮到你,实用的百度服务器的时间,如果没网络会使用系统默认时间! /*** 获取网络当 ...

  3. Swift实战-豆瓣电台(三)获取网络数据

    原文:Swift实战-豆瓣电台(三)获取网络数据 观看地址:http://v.youku.com/v_show/id_XNzMwMzQxMzky.html 这节内容,我们先说了怎么将storyboar ...

  4. C#获取网络时间(初学者)

    众所周知,许多游戏有每日登陆奖励,这里涉及到了时间,在联网的的情况下优先获取网络时间,在不联网的情况下只能获取本地时间了,但是本地时间可能容易会被修改,这是弊端.这里学习尝试获取网络时间. 获取网络时 ...

  5. android获取网络时区_Android获取系统时间以及网络时间

    项目开发中,很多时候会用到android的时间,罗列一下获取的时间的方式,和大家共同学习进步 一.获取系统时间 1.通过Calendar类来获取系统当前的时间 Calendar calendar = ...

  6. Android编程获取网络连接状态及调用网络配置界面

    获取网络连接状态 随着3G和Wifi的推广,越来越多的Android应用程序需要调用网络资源,检测网络连接状态也就成为网络应用程序所必备的功能. Android平台提供了ConnectivityMan ...

  7. 使用php需要网络吗,使用php获取网络文件

    如何使用PHP获取网络上文件 //设置我们将要使用的文件 $srcurl = "http://www.jquerycn.cn/index.php"; $tname = " ...

  8. Android之如何获取网络类型并判断是否可用

    ConnectivityManager主要管理和网络连接相关的操作,通过getSystemService(Context.CONNECTIVITY_SERVICE)获 取网络连接的服务.因此我们可以通 ...

  9. Android编程获取网络连接状态(3G/Wifi)及调用网络配置界面

    http://www.mobiletuts.me 获取网络连接状态 随着3G和Wifi的推广,越来越多的Android应用程序需要调用网络资源,检测网络连接状态也就成为网络应用程序所必备的功能. An ...

最新文章

  1. java字符串去重复_Java 8新特性:字符串去重
  2. 基于大数据与深度学习的自然语言对话
  3. 龙芯上市是自主路线被广泛认可的风向标
  4. 【Matlab】设置绘图窗口大小及颜色
  5. JS面向对象之创建对象
  6. Summed-Area Variance Soft Shadow Mapping(SAVSM):二
  7. 八 .数据库(多表查询)
  8. win10 默认程序 edge
  9. 2016中国大学生程序设计竞赛(长春)
  10. Steam 界面布局出错的问题
  11. 空气质量指数范围对应的类型有哪些?
  12. android 支付宝工具类,Android app第三方支付宝支付接入教程
  13. ROMS区域海洋模式的安装和运行
  14. 大数据是普惠金融的未来!
  15. 房租,社会教给年轻人的第一课
  16. 携程React Native实践
  17. Chap.19 总结《CL: An Introduction》 (Vyvyan Evans)
  18. 过年了,朋友圈放个收款二维码
  19. 云架构云原生 IaaS,PaaS,SaaS,Serverless
  20. 使用Python实现MP4格式视频与图片相互转换

热门文章

  1. 华为设备配置DHCP,旁挂式AC+AP无线局域网(3)
  2. 笨方法学python: ex20, 函数和文件
  3. mysql 电商实战_MySQL与电子商务实战
  4. 2022年全球及中国可重复使用食品包装行业头部企业市场占有率及排名调研报告
  5. 基于国密SM3算法(openssl接口)密钥派生函数KDF的实现
  6. 东华发思特巨杉数据库:打造智慧城市分布式大数据联合解决方案
  7. 基于区块链的医疗记录存储系统研究与开发
  8. 记录:不允许1130连接mysql_解决Navicat 报错:1130-host ... is not allowed to connect to this MySql server
  9. 火山坑随笔20180920_不能使用模拟器调试的问题
  10. matlab基础知识入门学习