iOS开发NSDate+Addition

释放双眼,带上耳机,听听看~!

date 转 string

///date 转 string
+ (NSString *)stringFromDate:(NSDate *)date dateFormatter:(NSString *)formatter {
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:formatter];
return [dateFormat stringFromDate:date];
}
/// date 转 string,  默认格式 @"yyyy年MM月dd日"
+ (NSString *)stringFromDate:(NSDate *)date {
return [self stringFromDate:date dateFormatter:@"yyyy年MM月dd日"];
}

string 转 date

///string 转 date
+ (NSDate *)dateFromString:(NSString *)timeStr dateFormatter:(NSString *)formatter {
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:formatter];
return [dateFormat dateFromString:timeStr];
}
///string 转 date,  默认格式 @"yyyy年MM月dd日"
+ (NSDate *)dateFromString:(NSString *)timeStr {
return [self dateFromString:timeStr dateFormatter:@"yyyy年MM月dd日"];
}

人已赞赏
iOS文章

iOS获取view的controller

2020-3-4 18:55:44

iOS文章

iOS开发第三方SSKeychain保存用户密码

2020-3-4 20:14:25

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
有新消息 消息中心
搜索