新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
VC++獲得當(dāng)前系統(tǒng)時間的幾種方案
//方案- 優(yōu)點:僅使用C標(biāo)準(zhǔn)庫;缺點:只能精確到秒級

安遠(yuǎn)網(wǎng)站制作公司哪家好,找創(chuàng)新互聯(lián)!從網(wǎng)頁設(shè)計、網(wǎng)站建設(shè)、微信開發(fā)、APP開發(fā)、成都響應(yīng)式網(wǎng)站建設(shè)公司等網(wǎng)站項目制作,到程序開發(fā),運營維護。創(chuàng)新互聯(lián)于2013年創(chuàng)立到現(xiàn)在10年的時間,我們擁有了豐富的建站經(jīng)驗和運維經(jīng)驗,來保證我們的工作的順利進行。專注于網(wǎng)站建設(shè)就選創(chuàng)新互聯(lián)。
- #include < time.h>
- #include < stdio.h>
- int main( void )
- {
- time_t t = time( 0 );
- char tmp[64];
- strftime( tmp, sizeof(tmp), " %Y/%m/%d %X %A 本年第%j天 %z" , localtime(&t) );
- puts( tmp );
- return 0;
- }
//方案二 優(yōu)點:能精確到毫秒級;缺點:使用了windows API
- #include < windows.h>
- #include < stdio.h>
- int main( void )
- {
- SYSTEMTIME sys;
- 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);
- return 0;
- }
//方案三,優(yōu)點:利用系統(tǒng)函數(shù)
- #include< stdlib.h>
- #include< iostream>
- using namespace std;
- void main(){
- system(" time" );
- }
可以改變電腦的時間設(shè)定
方案4:
- #include< iostream>
- #include< ctime>
- using namespace std;
- int main()
- {
- time_t now_time;
- now_time = time(NULL);
- cout< < now_time;
- return 0;
- }
另一:_strdate(tempstr);
另二: CTime
- CString CTestView::GetTime()
- {
- CTime CurrentTime=CTime::GetCurrentTime();
- CString strTime;
- strTime.Format(" %d:%d:%d" ,CurrentTime.GetHour(), CurrentTime.GetMinute()
- ,CurrentTime.GetSecond());
- return strTime;
- }
文章題目:VC++獲得當(dāng)前系統(tǒng)時間的幾種方案
文章網(wǎng)址:http://m.fisionsoft.com.cn/article/cccjojd.html


咨詢
建站咨詢
