日期对象的简单处理
来源:互联网 发布:mac apache 编辑:程序博客网 时间:2024/05/14 08:06
#=============================================== 计算指定日期n天以后的日期=========================
NSDateFormatter *inputFormatter= [[NSDateFormatter alloc] init];
[inputFormatter setLocale:[NSLocale currentLocale]];
[inputFormatter setDateFormat:@"yyyy.MM.dd"];
NSDate*inputDate = [inputFormatter dateFromString:@"2016.01.09"];
NSDateComponents *compt = [[NSDateComponents alloc] init];
//设置在2016.01.09的基础上加3天
NSCalendar *calendar = [NSCalendar currentCalendar];
NSDate *date = [calendar dateByAddingComponents:compt toDate:inputDate options:0];
//得到本地时间,避免时区问题
NSTimeZone *zone = [NSTimeZone systemTimeZone];
NSInteger interval = [zone secondsFromGMTForDate:date];
NSDate *localeDate = [date dateByAddingTimeInterval:interval];
NSDateFormatter *formatter =[[NSDateFormatter alloc] init];
formatter.dateFormat = @"yyyy.MM.dd";
NSString *endDate = [formatter stringFromDate:localeDate];
NSLog(@"===============%@==============",endDate);
#========================计算指定日期到现在的时间差 ======================
- (NSString *)intervalSinceNow: (NSString *) theDate
{
NSString *time = [theDate substringToIndex:theDate.length-2];
NSDateFormatter *date=[[NSDateFormatter alloc] init];
[date setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSDate *d=[date dateFromString:time];
NSTimeInterval late=[d timeIntervalSince1970]*1;
NSDate* dat = [NSDate dateWithTimeIntervalSinceNow:0];
NSTimeInterval now=[dat timeIntervalSince1970]*1;
NSString *timeString=@"";
NSTimeInterval cha=now-late;
if (cha/3600<1) {
timeString = [NSString stringWithFormat:@"%f", cha/60];
timeString = [timeString substringToIndex:timeString.length-7];
timeString=[NSString stringWithFormat:@"%@分钟前", timeString];
}
if (cha/3600>1&&cha/86400<1) {
timeString = [NSString stringWithFormat:@"%f", cha/3600];
timeString = [timeString substringToIndex:timeString.length-7];
timeString=[NSString stringWithFormat:@"%@小时前", timeString];
}
if (cha/86400>1)
{
timeString = [NSString stringWithFormat:@"%f", cha/86400];
timeString = [timeString substringToIndex:timeString.length-7];
timeString=[NSString stringWithFormat:@"%@天前", timeString];
}
return timeString;
}
- 日期对象的简单处理
- Jackson 日期对象的处理
- SQLSERVER 日期的简单处理
- 关于面向对象的日期处理源代码
- js日期对象兼容性的处理
- 简单日期处理
- Date对象中处理时间和日期的常用方法
- java -日期-Calendar 日期,天数,简单处理
- java日期处理简单封装
- java中Calendar日期对象的一些简单应用
- jquery简单对象处理
- 关于日期,java处理日期间隔的方法(简单实用)
- SQLServer的日期处理
- Java日期的处理
- Java 的 日期处理
- java的日期处理
- jstl 的日期处理
- python的日期处理
- ubuntu 安装Nginx + rtmp + ffmpeg
- PLpgsql语言中returning-into的使用方法 总结
- Ubuntu14.04 YouCompleteMe Configure
- A beginner's guide to writing a custom stream buffer (std::streambuf)
- 快速排序算法小结
- 日期对象的简单处理
- sqlserver与java数据类型对应
- PAT程序设计考题——甲级1006 签到问题(求所有签到人的最早时间和最晚时间)
- java打造手机远程控制电脑之详细教程
- 测试
- 【机器学习实战】笔记三:朴素贝叶斯算法
- 登录界面注册存储过程
- Log4j2介绍和特性实例(四)--过滤器Filter
- PAT程序设计考题——甲级1007 (最大连续子序列和)