-
date类型转换为字符串,格式可以在这个格式字符串中自定义,例如加上时分秒
-(NSString*)nsdateToString:(NSDate *)date { NSDateFormatter *dateFormat=[[NSDateFormatter alloc]init]; [dateFormat setDateFormat:@"yyyy-MM-dd"]; NSString* string=[dateFormat stringFromDate:date]; NSLog(@"%@",string); return string; }
-
字符串类型转换为NSDate
- (NSDate *)dateFromString:(NSString *)dateString { NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat: @"yyyy-MM-dd"]; NSDate *destDate= [dateFormatter dateFromString:dateString]; return destDate; }
网友评论