gmtime ()- 轉換時間

格式

#include <time.h>
struct tm *gmtime(const time_t *time);

語言層次

ANSI

安全執行緒

請改用 gmtime_r()

說明

The gmtime() function breaks down the 時間 value, in seconds, and stores it in a tm structure, defined in <time.h>. The value 時間 is usually obtained by a call to the time() function.

tm 結構的欄位包括:
tm_sec
秒 (0-61)
tm_min
分鐘 (0-59)
tm_hour
小時 (0-23)
tm_mday
日期 (1-31)
tm_mon
月 (0-11; 一月 = 0)
tm_year
年份 (現行年份減 1900)
tm_wday
星期幾 (0-6; 星期日 = 0)
tm_yday
一年中的第幾天 (0-365; 1 月 1 日 = 0)
tm_isdst
如果日光節約時間無效,則為零; 如果日光節約時間有效,則為正數; 如果資訊無法使用,則為負數。

回覆值

gmtime() 函數會將指標傳回至產生的 tm 結構。
附註:
  1. tm_sec 的範圍 (0-61) 最多容許兩個閏秒。
  2. gmtime()localtime() 函數可以使用一般靜態配置的緩衝區來進行轉換。 對其中一個函數的每一個呼叫可能會變更前一個呼叫的結果。
  3. 行事曆時間是自 EPOCH (即 00:00:00 , 1970 年 1 月 1 日「世界標準時間 (UTC)」) 以來所經歷的秒數。

範例

此範例使用 gmtime() 函數將 time_t 表示法調整為「世界標準時間」字串,然後使用 asctime() 函數將其轉換為可列印字串。
#include <stdio.h>
#include <time.h>
 
int main(void)
{
   time_t ltime;
 
   time(&ltime);
   printf ("Coordinated Universal Time is %s\n",
   asctime(gmtime(&ltime)));
}
 
/************************  Output should be similar to:  **********
 
Coordinated Universal Time is Wed Aug 18 21:01:44 1993
*/

相關資訊