
- The C Standard Library
- C Library - Home
- C Library - <assert.h>
- C Library - <ctype.h>
- C Library - <errno.h>
- C Library - <float.h>
- C Library - <limits.h>
- C Library - <locale.h>
- C Library - <math.h>
- C Library - <setjmp.h>
- C Library - <signal.h>
- C Library - <stdarg.h>
- C Library - <stddef.h>
- C Library - <stdio.h>
- C Library - <stdlib.h>
- C Library - <string.h>
- C Library - <time.h>
- C Standard Library Resources
- C Library - Quick Guide
- C Library - Useful Resources
- C Library - Discussion
- C Programming Resources
- C Programming - Tutorial
- C - Useful Resources
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C library function - gmtime()
Description
The C library function struct tm *gmtime(const time_t *timer) uses the value pointed by timer to fill a tm structure with the values that represent the corresponding time, expressed in Coordinated Universal Time (UTC) or GMT timezone.
Declaration
Following is the declaration for gmtime() function.
struct tm *gmtime(const time_t *timer)
Parameters
timeptr − This is the pointer to a time_t value representing a calendar time.
Return Value
This function returns pointer to a tm structure with the time information filled in. Below is the detail of timeptr structure −
struct tm { int tm_sec; /* seconds, range 0 to 59 */ int tm_min; /* minutes, range 0 to 59 */ int tm_hour; /* hours, range 0 to 23 */ int tm_mday; /* day of the month, range 1 to 31 */ int tm_mon; /* month, range 0 to 11 */ int tm_year; /* The number of years since 1900 */ int tm_wday; /* day of the week, range 0 to 6 */ int tm_yday; /* day in the year, range 0 to 365 */ int tm_isdst; /* daylight saving time */ };
Example
The following example shows the usage of gmtime() function.
#include <stdio.h> #include <time.h> #define BST (+1) #define CCT (+8) int main () { time_t rawtime; struct tm *info; time(&rawtime); /* Get GMT time */ info = gmtime(&rawtime ); printf("Current world clock:\n"); printf("London : %2d:%02d\n", (info->tm_hour+BST)%24, info->tm_min); printf("China : %2d:%02d\n", (info->tm_hour+CCT)%24, info->tm_min); return(0); }
Let us compile and run the above program that will produce the following result −
Current world clock: London : 14:10 China : 21:10
time_h.htm
Advertisements