[問題] 從網頁抓目前時間
-(void)getcurrentdate{
NSURL *url=[NSURL URLWithString:@"http://www.google.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
{
NSHTTPURLResponse *httpResponse=(NSHTTPURLResponse *)response;
if ([response respondsToSelector:@selector(allHeaderFields)]) {
NSDictionary *dic=[httpResponse allHeaderFields];
NSLog(@"dic:%@",dic);
NSString *time=[dic objectForKey:@"Date"];
}
小的使用這方式可以正確抓到時間目前,抓到的月份是英文的,
請問應該怎麼顯示數字的月份?用NSDateFormatter更改格式也沒用
上述的方式可以用afnetworking來取得嗎?
AFHTTPRequestOperation只是回傳整個網頁的html回來 沒有時間
上述的方式實在太慢了......
麻煩大大們幫忙! 謝謝!
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.32.162.165
推
10/24 19:47, , 1F
10/24 19:47, 1F
其實有先用這方式
NSDate *now = [NSDate date];
NSDateFormatter *TaipeiDateFormatter = [[NSDateFormatter alloc] init];
[TaipeiDateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
[TaipeiDateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"Asia/Taipei"]];
//[TaipeiDateFormatter setDateStyle:NSDateFormatterMediumStyle];
//[TaipeiDateFormatter setTimeStyle:NSDateFormatterMediumStyle];
NSString *TaipeiDateStr = [TaipeiDateFormatter stringFromDate:now];
//NSLog(@"TaipeiDateStr is %@",TaipeiDateStr);
NSDate *dateFromString1 = [[NSDate alloc] init];
dateFromString1 = [dateFormatter dateFromString:TaipeiDateStr];
NSLog(@"dateFromString1 is %@",dateFromString1);
這樣子不管使用者的時區在哪都可以用台灣的時間計算
但是另外的問題是使用者自己往前或往後調了10分鐘
這樣子就不是正確的時間
還有有任何offset的方式嗎?
※ 編輯: starkite 來自: 1.34.125.154 (10/24 20:20)
推
10/24 20:49, , 2F
10/24 20:49, 2F
→
10/24 21:25, , 3F
10/24 21:25, 3F
→
10/24 21:25, , 4F
10/24 21:25, 4F
推
10/24 23:52, , 5F
10/24 23:52, 5F
推
10/25 08:56, , 6F
10/25 08:56, 6F
MacDev 近期熱門文章
PTT數位生活區 即時熱門文章