NSDate日期的类
来源:互联网 发布:图像识别 python 编辑:程序博客网 时间:2024/05/16 13:06
一. //NSDate是一个日期的类
//1.date:无论在哪个时区,date获取的时间是相对应的零时区时间
NSDate *date=[NSDatedate];
NSLog(@"%@",date);
//2.先获取当前所在的时区
NSTimeZone *zone=[NSTimeZonesystemTimeZone];
NSLog(@"%@",zone);
//3.获取一下和0时区相差的秒数
NSInteger seconds=[zone secondsFromGMTForDate:date];
NSLog(@"%ld",seconds);
//4.通过相差的秒数,能获取到现在的时间
NSDate *localDate=[NSDatedateWithTimeIntervalSinceNow:seconds];
NSLog(@"%@",localDate);
NSDate *times=[NSDatedateWithTimeIntervalSince1970:0];
NSLog(@"%@",times); 1970-01-01 00:00:00 +0000
//5.找到明天的这个时间
NSDate *tomorrowTime=[NSDatedateWithTimeIntervalSinceNow:(seconds+24*3600)];
NSLog(@"%@",tomorrowTime);
//6.找到昨天的这个时间
NSDate *yesterdayTime=[NSDatedateWithTimeIntervalSinceNow:(seconds-24*3600)];
NSLog(@"%@",yesterdayTime);
//7.时间间隔,对应的double类型
//计算两个时间对象的时间间隔
NSTimeInterval interval=[tomorrowTime timeIntervalSinceDate:date];
NSLog(@"%g",interval);
//8.计算当前时间和固定时间的差值
NSDate *constTime=[NSDatedateWithTimeIntervalSinceNow:(seconds-7 *3600)];
NSTimeInterval intervalTime=[constTime timeIntervalSinceDate:date];
if (intervalTime < 60) {
NSLog(@"刚刚");
}elseif (intervalTime >=60 && intervalTime<=3600){
NSLog(@"%ld分钟前",(NSInteger)intervalTime/60);
}elseif (intervalTime > 3600 && intervalTime<3600*24){
NSLog(@"%ld小时前",(NSInteger)intervalTime/3600);
}
打印结果:1小时前
- NSDate日期的类
- NSDate 日期类的使用
- 日期时间类NSdate的使用
- Objective-C的日期类NSDate
- NSDate日期时间类
- NSDate 日期类型的使用
- NSDate 日期操作工具类
- OC - 时间日期类NSDate
- NSDate日期类封装大全
- NSDate 获取某个日期之前的日期
- NSDate日期时间、NSDateFormatter日期格式类
- NSDate --- 日期
- NSDate日期
- 日期类NSDate与日期格式化类NSDateFormatter类的使用
- iOS 日期(NSDate)的常用操作总结
- NSDate,日期格式的灵活输出
- NSDate与NSString的相互转化(日期)
- ios 操作日期NSDate
- WCF 绑定(Binding)
- H5点击及focus效果
- Error C0020001
- 安卓实习第七天
- 【mongodb系统学习之十】mongodb查询(一)
- NSDate日期的类
- 未处理的异常: 0xC0000005: 读取位置 0x00000000 时发生访问冲突
- C语言中的预编译指令
- 耻辱!
- Log4j2使用总结
- HDOJ 5305 Friends 暴力枚举
- zoj 3203 Light Bulb(公式推导|三分法)(简单)
- Android touch mode和focusableInTouchMode分析
- git基本使用