Linux 時間編程

Linux 時間編程

時間編程
#include<time.h>
time_t time(time_t *tloc) // 獲取日曆時間


struct tm *gmtime(const time_t *timep) // 將日曆時間轉化爲格林威治時間,並存至tm結構中
struct tm *localtime(const time_t 8timep)// 將日曆時間轉化爲本地時間,並保存在tm結構

時間顯示 
char *asctime(const struct tm *tm) // 將tm格式的時間轉換爲字符串
char *ctime(const time_t *timep) //將日曆時間轉換爲本地時間的字符串形式


獲取時間
int gettimeofday(struct timeval *tv, struct timezone *tz)
獲取從今日凌晨到現在的時間差,用於計算時間耗時
其參數tv是保存獲取時間結果的結構體,參數tz用於保存時區結果:
struct timezone{
int tz_minuteswest;/*格林威治時間往西方的時差*/
int tz_dsttime;/*DST 時間的修正方式*/
}
timezone 參數若不使用則傳入NULL即可。


延時執行
unsingned int sleep(unsigned int seconds)
//使程序睡眠seconds秒
void usleep(unsigned long usec)
//使程序睡眠usec微秒



struct tm{
int tm_sec;  // 秒
int tm_min;  // 分
int tm_hour; // 小時
int tm_mday; // 本月第幾日
int tm_mon;  // 月
int tm_year; // 年
int tm_wday; // 本週第幾日
int tm_yday;  // 本年第幾日
};


struct timeval{
int tv_sec; // 秒
int tv_usec; // 微秒
};
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章