C/c++/mfc Time Usage

Source: Internet
Author: User

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

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.