strptime strftime時間函數總結


time(2)

#include <time.h>

time_t time(time_t *timep);//獲取當前時間距離1970-01-01 00:00:00  經歷的秒數

p = struct tm *localtime(const time_t *timep);//根據上邊timep的值計算出本地時間,存放在返回指針的結構體中

其中p->tm_year + 1900,p->tm_mon + 1。

--------------------------------------------------------------------------------------------------------------------------------------------------

strptime

#define _XOPEN_SOURCE /* See feature_test_macros(7) */
#include <time.h>

char *strptime(const char *s, const char *format, struct tm *tm);/0./把指定時間s按照format的格式解析到tm中。mktime(3)函數

time_t mktime(struct tm *tm);//mktime(3)根據tm可以換算出時間s距離1970-01-01 00:00:00  經歷的秒數

編譯的時候出現錯誤: warning: implicit declaration of function ‘strptime’; did you mean ‘strftime’? [-Wimplicit-function-declaration]

 解決辦法:編譯的時候加上-D _XOPEN_SOURCE

-------------------------------------------------------------------------------------------------------------------------------------------------

strftime


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM