linux 時間程式設計

2021-05-28 18:00:56 字數 1358 閱讀 5619

時間獲取:

#include

time_t time(time_t *tloc)

struct tm* gmtime(const

time_t

timep)

將日曆時間轉化為格林威治標準時間,儲存在tm結構中。

struct tm* localtime(const time_t *timep)

將日曆時間轉化為本地時間,儲存在tm結構中。

tm結構中tm_year +1900=現在的年份。

struct tm {  

int tm_sec; /* 秒–取值區間為[0,59] */ 

int tm_min; /* 分 - 取值區間為[0,59] */

int tm_hour; /* 時 - 取值區間為[0,23] */ 

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

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

int tm_year; /* 年份,其值從1900開始 */ 

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

int tm_yday; /* 從每年的1月1日開始的天數–取值區間為[0,365],其中0代表1月1日,1代表1月2日,以此類推 */ 

int tm_isdst; /* 夏令時識別符號,實行夏令時的時候,tm_isdst為正。不實行夏令時的進候,tm_isdst為0;不了解情       

況時,tm_isdst()為負。*/

char* asctime(const struct tm *tn)

將tm格式時間轉化為字串如:

mon    jul 25 09:12:02  2007

char* ctime(const time_t* timep)

將日曆時間轉化為 本地時間字串

int gettimeofday(struct timeval* tv,struct timezone *tz)

獲取從今天凌晨到現在的時間差。

unsigned int sleep(unsigned int  seconds)

是程式睡眠 seconds秒。

void usleep(unsigned long usec)

使程式睡眠usec微秒;

linux時間程式設計

關於linux下時間程式設計的問題 1.linux下與時間有關的結構體 struct timeval 其中tv sec是由凌晨開始算起的秒數,tv usec則是微秒 10e 6 second struct timezone tv minuteswest是格林威治時間往西方的時差,tv dsttime...

linux 時間程式設計

一 時間型別介紹 1 utc coordinated universal time 世界標準時間,也就是格林威治時間 gmt 2 ct calendar time 日曆時間,從某個時間點開始到現在經過的秒數 二 標頭檔案 include 三 函式介紹 1 時間獲取 time t time time ...

linux 時間程式設計

從乙個標準時間 1900年1月1日0點 到此時經過的秒數 utc coordinated universal time 世界標準時間 即 gmt greenwich mean time 格林威治標準時間 標頭檔案 inclulde 函式time t time time t tloc 功能獲取日曆時間...