美文网首页
XML日期格式 转成NSDate

XML日期格式 转成NSDate

作者: 随缘吖 | 来源:发表于2016-12-06 17:11 被阅读98次
    • 获取一个webview 加载完成之后的时间,可认为服务器时间
    UIWebView * webView;
    NSCachedURLResponse * resp = [[NSURLCache sharedURLCache] cachedResponseForRequest:webView.request];
    NSLog(@" %@ ", [(NSHTTPURLResponse *)resp.response allHeaderFields]);
    
    webview 完成服务器时间

    将日期进行格式转换

      NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
      formatter.locale = [NSLocale localeWithLocaleIdentifier:@"en_US"];//日期语法
      formatter.dateFormat = @"EEE, dd MMM yyyy HH:mm:ss zzz";
      NSDate * date = [formatter dateFromString:@"Fri, 25 Nov 2016 11:26:31 GMT"];
      NSLog(@"%@",date);
    

    *** 转成时间戳的过程中,注意要设置 formatter的local 属性,当初就是在这个地方浪费了很长时间***

    相关文章

      网友评论

          本文标题:XML日期格式 转成NSDate

          本文链接:https://www.haomeiwen.com/subject/mhurmttx.html