自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

VC++獲得當(dāng)前系統(tǒng)時(shí)間的幾種方案

開發(fā) 后端
在開發(fā)應(yīng)用程序時(shí)往往需要獲取當(dāng)前系統(tǒng)時(shí)間。盡管Y2K似乎已經(jīng)平安過去,但在我們新開發(fā)的應(yīng)用程序中還是要謹(jǐn)慎處理“時(shí)間”問題。

//方案- 優(yōu)點(diǎn):僅使用C標(biāo)準(zhǔn)庫;缺點(diǎn):只能精確到秒級(jí)

 

  1. #include < time.h>   
  2. #include < stdio.h>   
  3. int main( void )   
  4. {   
  5. time_t t = time( 0 );   
  6. char tmp[64];   
  7. strftime( tmp, sizeof(tmp), " %Y/%m/%d %X %A 本年第%j天 %z" , localtime(&t) );   
  8. puts( tmp );   
  9. return 0;   
  10. }  

 

 

//方案二 優(yōu)點(diǎn):能精確到毫秒級(jí);缺點(diǎn):使用了windows API

 

  1. #include < windows.h>   
  2. #include < stdio.h>   
  3. int main( void )   
  4. {   
  5. SYSTEMTIME sys;   
  6. GetLocalTime( &sys );   
  7. printf( " %4d/%02d/%02d %02d:%02d:%02d.%03d 星期%1d\n"   
  8. ,sys.wYear,sys.wMonth,sys.wDay   
  9. ,sys.wHour,sys.wMinute,sys.wSecond,sys.wMilliseconds   
  10. ,sys.wDayOfWeek);   
  11. return 0;   
  12. }  

 

 

//方案三,優(yōu)點(diǎn):利用系統(tǒng)函數(shù)

 

  1. #include< stdlib.h>   
  2. #include< iostream>   
  3. using namespace std;   
  4. void main(){   
  5. system(" time" );   
  6. }  

 

可以改變電腦的時(shí)間設(shè)定

 

方案4:

 

  1. #include< iostream>   
  2. #include< ctime>   
  3. using namespace std;   
  4. int main()   
  5. {   
  6. time_t now_time;   
  7. now_time = time(NULL);   
  8. cout< < now_time;   
  9. return 0;   
  10. }  

 

 

另一:_strdate(tempstr);

另二: CTime

 

  1. CString CTestView::GetTime()   
  2. {   
  3. CTime CurrentTime=CTime::GetCurrentTime();   
  4. CString strTime;   
  5. strTime.Format(" %d:%d:%d" ,CurrentTime.GetHour(), CurrentTime.GetMinute()   
  6. ,CurrentTime.GetSecond());   
  7. return strTime;   

 

【編輯推薦】

  1. VC++如何將程序最小化到托盤
  2. VC++連MySQL中的一些小知識(shí)點(diǎn)
  3. 淺析VC++應(yīng)用程序環(huán)境
  4. 巧妙的進(jìn)行VC++6.0代碼編制
責(zé)任編輯:于鐵 來源: flyingfish
相關(guān)推薦

2010-10-09 14:32:23

mysql函數(shù)

2009-07-28 12:48:50

.net獲得當(dāng)前插入行

2010-08-06 11:28:51

DB2取得當(dāng)前時(shí)間

2010-01-27 17:42:58

VC++開發(fā)環(huán)境

2010-08-09 16:16:58

DB2取得當(dāng)前時(shí)間

2011-07-13 11:20:55

VC++ODBC

2010-08-17 17:39:23

DB2取得當(dāng)前時(shí)間

2010-08-13 10:50:15

DB2取得當(dāng)前時(shí)間

2010-01-21 17:22:21

VC++

2010-02-04 10:13:35

C++獲得系統(tǒng)時(shí)間

2010-08-02 10:52:31

DB2取得當(dāng)前時(shí)間

2010-01-27 15:11:17

VC++編譯異常

2010-01-26 13:29:46

VC++應(yīng)用程序

2010-07-27 12:33:14

DB2數(shù)據(jù)庫

2011-07-14 20:42:14

C++

2009-01-04 09:33:52

VC++GCC移植

2010-07-28 11:05:57

DB2數(shù)據(jù)庫

2010-01-28 15:56:38

VC++ 6.0編譯

2010-01-20 13:52:19

2010-03-24 09:06:02

Visual Stui
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)