您好,欢迎访问三七文档
当前位置:首页 > 临时分类 > VC++获得当前系统时间的几种方案
VC++获得当前系统时间的几种方案//方案—优点:仅使用C标准库;缺点:只能精确到秒级#includetime.h#includestdio.hintmain(void){time_tt=time(0);chartmp[64];strftime(tmp,sizeof(tmp),%Y/%m/%d%X%A本年第%j天%z,localtime(&t));puts(tmp);return0;}//方案二优点:能精确到毫秒级;缺点:使用了windowsAPI#includewindows.h#includestdio.hintmain(void){SYSTEMTIMEsys;GetLocalTime(&sys);printf(%4d/%02d/%02d%02d:%02d:%02d.%03d星期%1d\n,sys.wYear,sys.wMonth,sys.wDay,sys.wHour,sys.wMinute,sys.wSecond,sys.wMilliseconds,sys.wDayOfWeek);return0;}//方案三,优点:利用系统函数#includestdlib.h#includeiostreamusingnamespacestd;voidmain(){system(time);}可以改变电脑的时间设定方案4:#includeiostream#includectimeusingnamespacestd;intmain(){time_tnow_time;now_time=time(NULL);coutnow_time;return0;}另一:_strdate(tempstr);另二:CStringCTestView::GetTime(){CTimeCurrentTime=CTime::GetCurrentTime();CStringstrTime;strTime.Format(%d:%d:%d,CurrentTime.GetHour(),CurrentTime.GetMinute(),CurrentTime.GetSecond());returnstrTime;}language=VBScriptcallReplaceSubjectHTML_emote(592915)
本文标题:VC++获得当前系统时间的几种方案
链接地址:https://www.777doc.com/doc-2866010 .html