linux應用開發-時間編程

來源:互聯網
上載者:User

標籤:linux   應用   日曆   標準   

linux應用開發-時間編程

一 時間類型


世界標準時間:格林威治時間


日曆時間:從1970-1-1起的秒數


二 時間函數


1 擷取日曆時間


函數名


time


函數原形


time_t time(time_t *t)


函數功能


從1970年1月1日的時間,單位為秒


所屬標頭檔


#include<time.h>


返回值


成功返回時間的秒速


失敗返回-1




參數說明


儲存返回值












2 擷取格林威治時間


函數名


gmtime




函數原形


struct tm *gmtime(const time_t *timep)




函數功能


將日曆時間轉化為世界標準時間


所屬標頭檔


#include <time.h>


返回值


成功返回時間


失敗返回-1


參數說明


timep是日曆時間的地址












3 擷取本地時間


函數名


localtime


函數原形


struct tm *localtime(const time_t *timep) 


函數功能


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


所屬標頭檔


#include <time.h>


返回值


成功返回本地時間


失敗返回-1


參數說明


Timep是日曆時間的地址













4 以字串方式顯示時間


函數名


asctime


函數原形


char *asctime(const struct tm *tm)


函數功能


將標準時間轉化為字串方式顯示的時間


所屬標頭檔


#include <time.h>


返回值


成功返回字串指標存放的是字串時間


失敗返回-1




參數說明


參數是標準時間的結構體指標












5 擷取高精度時間


函數名


gettimeeofday


函數原形


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


函數功能


擷取高精度的時間


所屬標頭檔


#inlclude <sys/time.h>


返回值


成功返回0


失敗返回-1


參數說明


tv 儲存從1970-1-1-0到現在經曆的秒數和微秒數


tzone通常為NULL

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.