一、時間獲取
#include
time_t time(time_t * tloc)
功能:獲取日曆時間,既從2023年1月1日0點到現在所經歷的秒數
例子:
#include #include int main()
二、時間轉化
struct tm * gmtime(const time_t * timeep)
功能:將日曆時間轉化為格林威治標準時間,並儲存至tm結構
struct tm * localtime(const time_t * timep)
功能:將日曆時間轉化為本地時間,並儲存至tm結構
tm結構:
struct tm
三、時間顯示
char * asctime(const struct tm * tm)
功能:將tm格式的時間轉化為字串
char * ctime(const time_t * timep)
功能:將日曆時間轉化為本地時間的字串形式
#include #include int main()
四、獲取時間
int gettimeofday(struct timeval * tv, struct timezone * tz)
功能:獲取從今日凌晨到現在的時間差,常用於計算事件耗時
struct timeval
#include #include #include #include void function()
}}int main()
五、延時執行
unsigned int sleep(unsigned int seconds)
功能:是程式睡眠seconds秒
void usleep(unsigned long usec)
功能:使程式睡眠usec微秒
Linux下C語言程式設計 時間概念
1.時間表示 在程式當中,我們經常要輸出系統當前的時間,比如我們使用date命令的輸出結果.這個時候我們可以使用下面兩個函式 include time t time time t tloc char ctime const time t clock time函式返回從1970年1月1日0點以來的秒數...
Linux下C語言程式設計 時間概念
1.時間表示 在程式當中,我們經常要輸出系統當前的時間,比如我們使用date命令的輸出結果.這個時候我們可以使用下面兩個函式 include time t time time t tloc char ctime const time t clock time函式返回從1970年1月1日0點以來的秒數...
Linux下關於時間概念的C語言程式設計
abstract 在程式中,經常需要輸出系統的當前時間 計算程式的執行時間 使用計時器等。introduction 一 時間的型別 1.格林威治標準時間 coordinated universal time utc 是世界標準時間,即常說的格林威治標準時間 greenwich mean time,g...