标签:
一、获取时间
struct tm *tm;
time_t timep;int day = tm->tm_mday;//日
二、获取两个日期相差多少天
1、获取当前日期的天数
GetAbsDays(MyDate x) {
int i;
int month_day[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
int year = x.year - 1;
int days = year * 365 + year / 4 - year / 100 + year / 400;
if (x.year % 4 == 0 && x.year % 100 != 0 || x.year % 400 == 0)
month_day[1]++;
for (i = 0; i < x.month - 1; i++)
days += month_day[i];
days += x.day - 1;
return days;
}
2、GetAbsDays(MyDate1 )- SignDialog::GetAbsDays(MyDate2);
三、通过时间戳计算时间差
1、获取当前时间(秒)
time_t t = time(0);
2、保存时间
Data data;
data.copy((unsigned char *) &t, sizeof(t));
UserDefault::getInstance()->setDataForKey("time_1", data);
3、取时间
auto d = UserDefault::getInstance()->getDataForKey("time_1",Data());
time_t lastExitTime = *((time_t*)d.getBytes());
time_t currentTime= time(0);
time_t time=currentTime-lastExitTime;
4、换算为分钟
int k=time/60;
标签:
原文地址:http://blog.csdn.net/u012408019/article/details/46521609