1. Usage in c\c++
/* Strftime Example */#include <stdio.h>/* puts */#include <time.h>/* time_t, struct TM, Time, Lo Caltime, strftime */int main () {time_t rawtime;struct tm * Timeinfo;char buffer [80];time (&rawtime); timeinfo = Localt IME (&rawtime); Strftime (buffer,80, "Now it ' s%m/%d/%y,%h:%m:%s.", Timeinfo);p UTS (buffer); return 0;}
2.MFC usage
CString str; Get system Time CTime TM; Tm=ctime::getcurrenttime (); Str=tm. Format ("Now time is%y year%m month%d day%x"); MessageBox (STR,NULL,MB_OK);
3. Get the number of seconds between two time string differences
CString sdatetime1,sdatetime2;sdatetime1 = S1.c_str (); sDateTime2 = S2.c_str (); int nyear, Nmonth, Ndate, Nhour, NMin, NSec ; sscanf (sDateTime1, "%d/%d/%d-%d:%d:%d", &nmonth, &ndate, &nyear, &nhour, &nmin, &nsec); nYear +=2000; CTime sTime1 (Nyear, Nmonth, Ndate, Nhour, NMin, NSEC); SSCANF (sDateTime2, "%d/%d/%d-%d:%d:%d", &nmonth, &ndate, &nyear, &nhour, &nmin, &nsec); NYear + = 2000; CTime sTime2 (Nyear, Nmonth, Ndate, Nhour, NMin, NSEC); CTimeSpan span = Stime2-stime1;span. Gettotalseconds ();
C/c++/mfc Time Usage