计算两个时间相距离多少
2012-04-14 09:20
183 查看
//得到当前日期
CFAbsoluteTime currTime=CFAbsoluteTimeGetCurrent();
CFGregorianDate currenttDate=CFAbsoluteTimeGetGregorianDate(currTime,CFTimeZoneCopyDefault());
//得到要提醒的日期
CFGregorianDate clockDate=CFAbsoluteTimeGetGregorianDate(currTime, CFTimeZoneCopyDefault());
clockDate.hour=5;
clockDate.minute=10;
clockDate.second=1;
NSLog(@"currdata,year=%ld",currenttDate.year);
//把两个日期存放到tm类型的变量中
struct tm t0,t1;
t0.tm_year=currenttDate.year - 1900;
t0.tm_mon=currenttDate.month;
t0.tm_mday=currenttDate.day;
t0.tm_hour=currenttDate.hour;
t0.tm_min=currenttDate.minute;
t0.tm_sec=currenttDate.second;
t1.tm_year=clockDate.year - 1900;
t1.tm_mon=clockDate.month;
t1.tm_mday=clockDate.day;
t1.tm_hour=clockDate.hour;
t1.tm_min=clockDate.minute;
t1.tm_sec=clockDate.second;
NSLog(@"%d",t1.tm_yday);
NSLog(@"time1=%ld ,time2=%ld",mktime(&t1),mktime(&t0));
NSTimeInterval time=mktime(&t1)-mktime(&t0);
if (time<0) {
t1.tm_wday++;
time=mktime(&t1)-mktime(&t0);
}
NSLog(@"相差%f秒",time);
CFAbsoluteTime currTime=CFAbsoluteTimeGetCurrent();
CFGregorianDate currenttDate=CFAbsoluteTimeGetGregorianDate(currTime,CFTimeZoneCopyDefault());
//得到要提醒的日期
CFGregorianDate clockDate=CFAbsoluteTimeGetGregorianDate(currTime, CFTimeZoneCopyDefault());
clockDate.hour=5;
clockDate.minute=10;
clockDate.second=1;
NSLog(@"currdata,year=%ld",currenttDate.year);
//把两个日期存放到tm类型的变量中
struct tm t0,t1;
t0.tm_year=currenttDate.year - 1900;
t0.tm_mon=currenttDate.month;
t0.tm_mday=currenttDate.day;
t0.tm_hour=currenttDate.hour;
t0.tm_min=currenttDate.minute;
t0.tm_sec=currenttDate.second;
t1.tm_year=clockDate.year - 1900;
t1.tm_mon=clockDate.month;
t1.tm_mday=clockDate.day;
t1.tm_hour=clockDate.hour;
t1.tm_min=clockDate.minute;
t1.tm_sec=clockDate.second;
NSLog(@"%d",t1.tm_yday);
NSLog(@"time1=%ld ,time2=%ld",mktime(&t1),mktime(&t0));
NSTimeInterval time=mktime(&t1)-mktime(&t0);
if (time<0) {
t1.tm_wday++;
time=mktime(&t1)-mktime(&t0);
}
NSLog(@"相差%f秒",time);
相关文章推荐
- 两个字符串形式的时间计算相差多少
- oracle 计算两个时间之间的月份差,相差几个星期,相差多少天
- 计算两个时间 相差多少时分秒
- 计算两个时间相隔多少时间段的类,可以直接拿来用哦!
- javascript 精准计算两个时间间相差多少年月日时分秒
- 计算格式为YYYY-MM-DD HH:ii:ss的两个时间,相差多少年、多少月、多少日、多少小时、多少分钟、多少秒?
- 根据指定两个日期计算出这些时间内有多少天是周末 php程序函数代码
- 如何计算两个时间相差多少周年
- JAVA中计算两个时间相差多少 天,时,分,秒
- 计算两个时间之间相差了多少时间
- 根据指定两个日期计算出这些时间内有多少天是周末 php程序函数代码
- 计算两个时间相差多少年月日的sql算法
- db2 怎么计算两个时间相差多少个月。如2015-10-10 和2014-1-12
- c语言:输入两个整数m和n,计算需要改变m的二进制表示中的多少位才能得到n
- python两个关于计算方法运行时间的修饰器
- C#日期比较计算两个日期的时间间隔,日期格式化
- 计算两个日期相差多少天!
- JS获取系统时间、计算两个日期天数、比较日期大小
- java 计算两个时间之间的间隔
- 两个时间相差多少 .net中的timespan应用