日期分类
来源:互联网 发布:好玩的java web项目 编辑:程序博客网 时间:2024/05/19 15:20
- (NSDateComponents *)componentsOfDay {
return [[NSCalendarcurrentCalendar]components:NSCalendarUnitYear |NSCalendarUnitMonth|NSCalendarUnitDay|NSCalendarUnitWeekday|NSCalendarUnitHour|NSCalendarUnitMinute|NSCalendarUnitSecondfromDate: self];
}
- (BOOL)isEqualToDateIgnorTime:(NSDate *)date
{
NSDateComponents *components = [selfcomponentsOfDay];
NSDateComponents *componentd = [datecomponentsOfDay];
return (componentd.year == components.year && components.month == componentd.month && components.day == componentd.day);
}
- (NSString *)stringWithExcludeThisYear {
BOOL isThisYear =NO;
NSDate *nowDate = [NSDatedate];
if ([nowDatecomponentsOfDay].year != [selfcomponentsOfDay].year) {
isThisYear =NO;
}else{
isThisYear =YES;
}
NSDateFormatter *formatter = [[NSDateFormatteralloc]init];
if (isThisYear) {
[formatter setDateFormat:@"MM月dd日"];
}else{
[formatter setDateFormat:@"yyyy年MM月dd日"];
}
return [formatterstringFromDate:self];
}
//判断是否是今天
- (BOOL)isToday {
NSDate *date = [NSDatedate];
return [selfisEqualToDateIgnorTime:date];
}
//判断是否是昨天
- (BOOL)isYesterDay {
NSTimeInterval time = [[NSDatedate]timeIntervalSince1970]-24*60*60;
NSDate *yesterDayDate = [NSDatedateWithTimeIntervalSince1970:time];
return [selfisEqualToDateIgnorTime:yesterDayDate];
}
+(NSString *)stringWithTimeInterval:(NSTimeInterval)time {
NSDate *date = [NSDatedateWithTimeIntervalSince1970:time];
NSInteger hour = [datecomponentsOfDay].hour;
NSInteger minute = [datecomponentsOfDay].minute;
NSTimeInterval nowTime = [[NSDatedate]timeIntervalSince1970];
if (nowTime - time>=7*24*60*60) {
NSDateFormatter *formatter = [[NSDateFormatteralloc]init];
[formatter setDateFormat:@"yyyy年MM月dd日 HH:mm"];
return [formatterstringFromDate:date];
}else{
if ([dateisToday]) {
return [NSStringstringWithFormat:@"今天 %ld:%ld",hour,minute];
}elseif ([date isYesterDay]){
return [NSStringstringWithFormat:@"昨天 %ld:%ld",hour,minute];
}else{
NSArray *weekInfo =@[@"星期日",@"星期一",@"星期二",@"星期三",@"星期四",@"星期五",@"星期六"];
NSInteger weekDay = [datecomponentsOfDay].weekday;
NSString *weekString = weekInfo[weekDay -1];
return [NSStringstringWithFormat:@"%@ %ld:%ld",weekString, hour,minute];
}
}
}
- 日期分类
- mysql 日期各种分类查询
- NSDate分类-日期格式化以及日期常用判断
- 构造存储路径名:分类表名+日期+序号
- 将文件根据不同日期进行分类(文件归档)
- 分类
- 分类
- 分类
- 分类
- 分类
- 分类
- 分类
- 分类
- 分类
- 分类
- 分类
- 分类
- 分类
- STL几个(set map vector string)用法
- Java学习第十七天
- HADOOP 集群安装配置
- Java Annotation详解+自定义java注解(一)
- 每天学点java—文档注释
- 日期分类
- 利用RANSAC算法筛选SIFT特征匹配
- List、Set、Map集合存放null解析及HashMap、Hashtable异同点解析
- JAVA学习笔记(四)
- Eratosthenes筛法
- UVALive - 4287 Proving Equivalences(强连通分量 + DAG)
- 10271 - Chopsticks
- 2015ZZUACM暑期集训
- AT指令发送短信流程