//获取网络时间
+ (NSString *)getTimeLine
{
NSString *urlString = @"http://m.baidu.com";
urlString = [urlString stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
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 *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];
NSTimeZone *zone = [NSTimeZone systemTimeZone];
NSInteger interval = [zone secondsFromGMTForDate: netDate];
//当前时间,时分秒
NSDate *localeDate = [netDate dateByAddingTimeInterval: interval];
//再转换成毫秒
NSTimeInterval logDateInterval= [localeDate timeIntervalSince1970];
long long logTime= logDateInterval*1000;
//默认是秒,毫秒 时间戳*1000 ,想取得微秒 时间戳 * 1000 * 1000
return [NSString stringWithFormat:@"%lld", logTime];
}
//获取本地时间;
+ (NSString *)getTimeLine
{
return [NSString stringWithFormat:@"%lld", (long long)([[NSDate date]timeIntervalSince1970] * 1000)];
}