zoukankan      html  css  js  c++  java
  • 获取网络时间

    - (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;
    
    }

     

    为了更好点交流和学习,请大家在参阅博客后,留下你的疑问和宝贵意见。谢谢!!!!
  • 相关阅读:
    Codeforces Ilya and Matrix
    poj 1308 Is It A Tree?
    Codeforces Sereja and Array
    poj 1041 John's trip
    Codeforces Continued Fractions
    WM_COPYDATA实现进程间数据通信
    虚拟机中安装ubuntu后,终端模式和图形模式切换
    IIS上配置运行cgi,php,aspx运行环境
    linux c main函数参数
    Linux网络编程入门 (转载)
  • 原文地址:https://www.cnblogs.com/fshmjl/p/4827395.html
Copyright © 2011-2022 走看看