LINUX學習筆記10——時間編程

來源:互聯網
上載者:User

a)         需要包涵標頭檔:#include<time.h>
 
b)         時間類型:
 
1.         格林威治標準時間:
 
2.         日曆時間:從一個標準的時間點到此時經過的秒數來表示的時間,本質是秒數
 
c)         擷取日曆時間:time_t time(time_t *tloc):返回的是秒數
 
1.         T=time(NULL);
 
d)         時間轉化:
 
1.         日曆時間轉化為格林威治時間:struct tm *gmtime(const time_t *timep)
 
a)         timep:是用來儲存時間的時間變數的地址
 
b)         time_t t:定義時間變數
 
2.         日曆時間轉化為本地時間:struct tm *localtime(const time_t *timep)
 
3.         儲存至TM結構
 
Struct tm{
 
Int tm_sec;
 
Int tm_min;
 
Int tm_hour;
 
Int tm_mday;
 
Int tm_mon;
 
Int tm_year; 相對值,需要+1900
 
Int tm_wday;
 
Int tm_yday; 本年第幾日
 
Int tm_isdst;};  日光節約時間
 
4.         將tm格式的時間轉化為字串,便於顯示
 
a)         Char *asctime(const struct tm *tm)
 
5.         將日曆時間轉化為本地時間的字串,便於顯示
 
a)         Char *ctime(const time_t *timep)
 
6.         擷取從今日淩晨到現在的時間差,常用於時間耗時,結束時間-初始時間
 
a)         Int gettimeofday(struct timeval *tv, struct timezone *tz)
 
b)         Struct timeval{  用來存放秒數
 
c)         Int tv_sec;   用來存放秒數
 
d)         Int tv_usec;};   用來存放微秒
 
7.         使程式睡眠sec秒:
 
a)         Unsigned int sleep(unsigned int seconds)
 
8.         使程式睡眠usec微秒:
 
a)         void usleep(unsigned long seconds)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.