cocos2d-x3.3 Get Time

Source: Internet
Author: User


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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.