I. Acquisition of TIME
struct TM *tm;
time_t TIMEP;
#if (Cc_target_platform = = Cc_platform_win32)
Time (&TIMEP);
#else
struct Timeval TV;
Gettimeofday (&TV, NULL);
TIMEP = tv.tv_sec;
#endif
TM = LocalTime (&TIMEP);
int year = Tm->tm_year + 1900;//
Int month = Tm->tm_mon + 1;//Month
int day = tm->tm_mday;//
Ii. How many days to obtain the difference between two dates
1. Get the number of days of the current date
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%!! = 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);
Third, calculate time difference by timestamp
1. Get current time (seconds)
time_t t = time (0);
2. Save time
Data data;
Data.copy ((unsigned char *) &t, sizeof (t));
Userdefault::getinstance ()->setdataforkey ("Time_1", data);
3, take the time
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. Conversion to minutes
int k=time/60;
cocos2d-x3.3 Get Time