c語言獲取本地時間

2021-07-03 01:31:59 字數 667 閱讀 6850

c語言獲得本地時間

需要用到時間函式庫中的結構體指標struct tm*ptr和獲取時間(單位為秒)的長整型time_t;

#include#include#includeint main()  

/* 

13.struct tm { 

14. 

15.int tm_sec;  秒–取值區間為[0,59]  

16. 

17.int tm_min;  分 - 取值區間為[0,59]  

18. 

19.int tm_hour;  時 - 取值區間為[0,23]  

20. 

21.int tm_mday;  乙個月中的日期 - 取值區間為[1,31]  

22. 

23.int tm_mon;  月份(從一月開始,0代表一月) - 取值區間為[0,11]  

24. 

25.int tm_year;  年份,其值從1900開始  

26. 

27.int tm_wday;  星期–取值區間為[0,6],其中0代表星期天,1代表星期一,以此類推  

28. 

29.*/

挺好玩的^-^!!





獲取本地時間

獲取本地時間戳 int gettimestamp timeval tm gettimeofday tm,null return tm.tv sec 單位 秒 return tm.tv usec 單位 毫秒 獲取本地時間 time t t time null tm lt localtime t int...

獲取本地時間

獲取本地時間 struct tm tm time t timep if cc target platform cc platform win32 else localtime 功能 把從1970 1 1零點零分到當前時間系統所偏移的秒數時間轉換為日曆時間。說明 此函式獲得的tm結構體的時間,是已經進...

Linux獲取本地時間

參考鏈結 linux核心中表示時間的結構體和資料型別有5種,具體其宣告的標頭檔案在 include include extern void do gettimeofday struct timeval tv gettimeofday函式執行成功後返回0,失敗後返回 1,錯誤 存於errno中。ext...