VC 獲得當前系統時間的幾種方案

2021-04-25 16:12:05 字數 841 閱讀 2097

//方案— 優點:僅使用c標準庫;缺點:只能精確到秒級

#include

#include

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;

//方案二 優點:能精確到毫秒級;缺點:使用了windows api

#include

#include

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;

//方案三 優點:利用系統函式

#include

#include

using namespace std;

void main() language=vbscript>call replacesubjecthtml_emote(592915)

VC 獲得當前系統時間的幾種方案

方案 優點 僅使用c標準庫 缺點 只能精確到秒級 include include int main void size t strftime char strdest,size t maxsize,const char format,const struct tm timeptr 根據格式字串生成字...

VC 獲得當前系統時間的幾種方案

方案 優點 僅使用c標準庫 缺點 只能精確到秒級 include time.h include stdio.h intmain void 方案二 優點 能精確到毫秒級 缺點 使用了windows api include windows.h include stdio.h intmain void 方...

收藏 VC 獲得當前系統時間的幾種方案

方案 優點 僅使用c標準庫 缺點 只能精確到秒級 include include 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 ret...