0
您好我做出這給了我一個約會的URL在像www.google.com/2012-10-09使URL字符串日期選擇器
末但由於某些原因,它不重定向代碼我到正確的網址? 似乎有理解NSURL URLwithstring有問題嗎?
這裏是我的代碼
- (IBAction)sedato:(id)sender {
//Finds date and make string
NSDate *ddato = [_datepickout date];
NSString *vdato = [NSString stringWithFormat:@"%@", ddato];
NSDateFormatter *datoform = [[NSDateFormatter alloc] init];
[datoform setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]];
[datoform setDateFormat: @"yyyy-MM-dd HH:mm:ss Z"];
NSDate *datemedform = [datoform dateFromString: vdato];
NSString *strdate = [[NSString alloc] initWithFormat:@"%@", datemedform];
NSArray *arr = [strdate componentsSeparatedByString:@" "];
NSString *endelig;
endelig = [arr objectAtIndex:0];
NSArray *arr2 = [endelig componentsSeparatedByString:@"-"];
NSString *year;
year = [arr2 objectAtIndex:0];
NSString *mm;
mm = [arr2 objectAtIndex:1];
NSString *dag;
day = [arr2 objectAtIndex:2];
NSString *url = [NSString stringWithFormat:@"http://www.coutbound.dk/logon/add_date.asp?view_date=%@/%@/%@",year,mm,day];
//Send url request with string
ASIFormDataRequest *request2 = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:url]];
[request2 setUseKeychainPersistence:YES];
[request2 setUseCookiePersistence:YES];
[request2 setDelegate:self];
[request2 startAsynchronous];
}
- (void)requestFinished:(ASIHTTPRequest *)request {
NSLog(@"Saved form successfully");
NSLog(@"Response was:");
NSLog(@"%@",[request responseString]);
NSLog(@"HEADERS: %@",[request responseHeaders]);
NSLog(@"STATUSCODE: %u",[request responseStatusCode]);
NSLog(@"COOkies: %@",[request responseCookies]);
}
集
檢查結果dateformatter您需要的格式爲yyyy/MM/DD和NSDateFormatter有方法,它返回從日期字符串[datoform stringFromDate:_datepickout 。日期] –