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

2021-06-20 18:45:31 字數 1466 閱讀 5587

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

#include

#include

int main( void )

size_t strftime(char *strdest, size_t maxsize, const char *format, const struct tm *timeptr); 

根據格式字串生成字串。 

struct tm *localtime(const time_t *timer); 

取得當地時間,localtime獲取的結果由結構tm返回 

返回的字串可以依下列的格式而定: 

%a 星期幾的縮寫。eg:tue 

%a 星期幾的全名。 eg: tuesday 

%b 月份名稱的縮寫。 

%b 月份名稱的全名。 

%c 本地端日期時間較佳表示字串。 

%d 用數字表示本月的第幾天 (範圍為 00 至 31)。日期 

%h 用 24 小時制數字表示小時數 (範圍為 00 至 23)。 

%i 用 12 小時制數字表示小時數 (範圍為 01 至 12)。 

%j 以數字表示當年度的第幾天 (範圍為 001 至 366)。 

%m 月份的數字 (範圍由 1 至 12)。 

%m 分鐘。 

%p 以 ''am'' 或 ''pm'' 表示本地端時間。 

%s 秒數。 

%u 數字表示為本年度的第幾周,第乙個星期由第乙個週日開始。 

%w 數字表示為本年度的第幾周,第乙個星期由第乙個周一開始。 

%w 用數字表示本週的第幾天 ( 0 為週日)。 

%x 不含時間的日期表示法。 

%x 不含日期的時間表示法。 eg: 15:26:30 

%y 二位數字表示年份 (範圍由 00 至 99)。 

%y 完整的年份數字表示,即四位數。 eg:2008 

%z(%z) 時區或名稱縮寫。eg:中國標準時間 

%% % 字元。 

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

#include

#include

int main( void )

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

#include

#include

using namespace std;

void main()

可以改變電腦的時間設定

方案4:

#include

#include

using namespace std;

int main()

另一:_strdate(tempstr);

另二:cstring ctestview::gettime()

language=vbscript>call replacesubjecthtml_emote(592915)

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...

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...