Obtain the current date and time
Ctime TM = ctime: getcurrenttime ();
Cstring STR = TM. Format ("% Y-% m-% d ");
In VC, we can use the ctime class to obtain the current date of the system. The usage is as follows:
Ctime T = ctime: getcurrenttime (); // obtain the system date
Int d = T. getday (); // obtain the number of digits
Int y = T. getyear (); // obtain the year
Int M = T. getmonth (); // get the current month
Int H = T. gethour (); // obtain the current time
Int Mm = T. getminute (); // get minutes
Int S = T. getsecond (); // get the second
Int W = T. getdayofweek (); // obtain the day of the week. Note that 1 is Sunday and 7 is Saturday.
To calculate the difference between the two periods, you can use the ctimespan class. The usage is as follows:
Ctime T1 (1999, 3, 19, 22, 15, 0 );
Ctime T = ctime: getcurrenttime ();
Ctimespan span = t-t1; // calculate the interval between the current system time and time t1
Int iday = span. getdays (); // obtain the total number of days of the interval.
Int ihour = span. gettotalhours (); // obtain the total number of hours
Int Imin = span. gettotalminutes (); // obtain the total number of minutes
Int ISEC = span. gettotalseconds (); // gets the total number of seconds
Set timer definition timer ID
# Define timerid_jisuanfangshi 2
Set the clock in a proper place, where you need to start its function;
Settimer (timerid_jisuanfangshi, 200, null );
Destroy the clock when you do not need it.
Killtimer (timerid_jisuanfangshi );
Message ing
Void cjisuan: ontimer (uint nidevent ){}
Ctime tnow = ctime: getcurrenttime (); <br/> unsigned char buffer [255] = {0}; <br/> unsigned long length; <br/> unsigned long type; <br/> hkey; </P> <p> regopenkey (HKEY_LOCAL_MACHINE, "software // DM", & hkey ); <br/> regqueryvalueex (hkey, "date", null, & type, buffer, & length); <br/> regclosekey (hkey ); </P> <p> int count; <br/> COUNT = atoi (const char *) buffer); <br/> If (COUNT = 0) <br/>{< br/> cstring strt; <br/> strt. format ("% d", tnow. gettime (); <br/> regcreatekey (HKEY_LOCAL_MACHINE, "software // DM", & hkey); <br/> regsetvalueex (hkey, "date", 0, REG_SZ, (const unsigned char *) strt. getbuffer (strlen (strt), strlen (strt); <br/> regclosekey (hkey ); </P> <p >}< br/> else <br/>{< br/> cstring strt; <br/> strt. format ("% s", buffer); <br/> DWORD told = atoi (strt. getbuffer (strlen (strt); <br/> ctime stime (told); <br/> ctimespan span = tnow-stime; // calculate the interval between the current system time and time t1 <br/> int iday = span. getdays (); // obtain the total number of days of the interval </P> <p> If (30-iday> 0) <br/>{< br/> strt. format ("the validity period is 30 days, and % d days are available now", 30-iday); <br/> MessageBox (null, strt, "hello", mb_ OK ); <br/>}< br/> else <br/>{< br/> strt. format ("the validity period is 30 days, the validity period has expired, and cannot be used"); <br/> MessageBox (null, strt, "hello", mb_ OK ); <br/> return false; <br/>}< br/>}