Linux下獲得系統時間的C語言的實現方法

來源:互聯網
上載者:User

Linux下獲得系統時間的C語言的實現方法

 

#include<time.h>  //C語言的標頭檔
#include<stdio.h>  //C語言的I/O

void main()
{
time_t now;    //執行個體化time_t結構
struct tm  *timenow;    //執行個體化tm結構指標
time(&now);
//time函數讀取現在的時間(國際標準時間非北京時間),然後傳值給now

timenow = localtime(&now);
//localtime函數把從time取得的時間now換算成你電腦中的時間(就是你設定的地區)

printf("Local time is %s/n",asctime(timenow));
//上句中asctime函數把時間轉換成字元,通過printf()函數輸出
}

注釋:time_t是一個在time.h中定義好的結構體。而tm結構體的原形如下:

struct tm
{
  int tm_sec;//seconds 0-61
  int tm_min;//minutes 1-59
  int tm_hour;//hours 0-23
  int tm_mday;//day of the month 1-31
  int tm_mon;//months since jan 0-11
  int tm_year;//years from 1900
  int tm_wday;//days since Sunday, 0-6
  int tm_yday;//days since Jan 1, 0-365
  int tm_isdst;//Daylight Saving time indicator
};


上一篇:《如何編寫 linux 裝置驅動程式》
下一篇:《執行個體解讀 linux 網卡驅動》

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.