首页 > 代码库 > NSDate、NSString、long转化
NSDate、NSString、long转化
- (NSDate*)dateFromString:(NSString*)dateString{
NSDateFormatter*dateFormatter=[[NSDateFormatteralloc]init];
[dateFormattersetDateFormat:@"yyyy-MM-ddHH:mm:ss"];
NSDate*destDate= [dateFormatterdateFromString:dateString];
returndestDate;
}
- (NSString*)stringFromDate:(NSDate*)date{
NSDateFormatter*dateFormatter=[[NSDateFormatteralloc]init];
//zzz表示时区,zzz可以删除,这样返回的日期字符将不包含时区信息。
[dateFormattersetDateFormat:@"MM-ddHH:mm"];
NSString*destDateString =[dateFormatter stringFromDate:date];
returndestDateString;
}
-(NSString*)stringFromValue:(NSString*)value{
NSDate*confromTimesp=[NSDatedateWithTimeIntervalSince1970:[valuelongLongValue]];
NSDateFormatter*formatter=[[NSDateFormatteralloc]init];
[formattersetDateFormat:@"MM-ddHH:mm"];
NSString*date =[formatter stringFromDate:confromTimesp];
returndate;
}
NSDate、NSString、long转化