gmtime_r ()- 轉換時間 (可重新啟動)

格式

#include <time.h>
struct tm *gmtime_r(const time_t *time, struct tm *result);

語言層次

XPG4

安全執行緒

說明

此功能是可重新啟動的 gmtime()版本。

gmtime_r() 函數會以秒為單位來分解 時間 值,並將它儲存在 result中。 結果 is a pointer to the tm structure, defined in <time.h>. The value time 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_r() 函數會將指標傳回至產生的 tm 結構。
附註:
  1. tm_sec 的範圍 (0-61) 最多容許兩個閏秒。
  2. gmtime()localtime() 函數可以使用一般靜態配置的緩衝區來進行轉換。 對其中一個函數的每一個呼叫可能會變更前一個呼叫的結果。 asctime_r()ctime_r()gmtime_r()localtime_r() 函數不使用一般靜態配置的緩衝區來保留傳回字串。 如果需要重新進入,這些函數可以用來取代 asctime()ctime()gmtime()localtime() 函數。
  3. 行事曆時間是自 EPOCH (即 00:00:00 , 1970 年 1 月 1 日「世界標準時間 (UTC)」) 以來所經歷的秒數。

範例

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

相關資訊