使用NSDate将日期保存到NSString中,但是日期变为000.000。
NSDate* date = [NSDate date];
NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyy-MM-dd HH:MM:SS"];
NSString* str = [formatter stringFromDate:date];
NSString*content_AddedTime=str;
NSString *post =[[NSString alloc] init];
post = [NSString stringWithFormat:@"userId=%@&catalogID=%@&content_AddedTime=%@&organizationCode=%@",userId,catalogID,content_AddedTime,organizationCode];
你可以先用NSLog来输出一下NSDate返回的格式
NSLog(@"current date:%@",date);
根据返回的日期格式来设置正确的formatter
[formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];