gmtime() Function in C Last Updated : 06 Oct, 2023 Comments Improve Suggest changes 2 Likes Like Report The gmtime() function in C takes a pointer to type t_time value which represents type in seconds and converts it to struct tm. In this article, we will learn gmtime() Function in the C programming language. The struct tm type can hold the individual components of time in UTC(Universal Time Coordinated) or GMT time (i.e., the time in the GMT timezone) time zones. The C gmtime() function is defined in <ctime> header file. Syntax of gmtime()tm* gmtime ( const time_t* current_time )The hours can be accessed using tm_hourThe minutes can be accessed using tm_minThe seconds can be accessed using tm_secParameterscurrent_time: It specifies a pointer to a time_t object.Return ValueOn Success, returns a pointer to a tm object.Otherwise, the Null pointer is returned.Examples of gmtime()Example 1 C // C program to illustrate the gmtime() function #include <stdio.h> #include <time.h> #define CST (+8) #define IND (-5) int main() { // object time_t current_time; // pointer struct tm* ptime; // use time function time(¤t_time); // gets the current-time ptime = gmtime(¤t_time); // print the current time printf("Current time:\n"); printf("Beijing ( China ):%2d:%02d:%02d\n", (ptime->tm_hour + CST) % 24, ptime->tm_min, ptime->tm_sec); printf("Delhi ( India ):%2d:%02d:%02d\n", (ptime->tm_hour + IND) % 24, ptime->tm_min, ptime->tm_sec); return 0; } OutputCurrent time: Beijing ( China ):20:00:04 Delhi ( India ): 7:00:04Example 2 C // C++ program to illustrate the // gmtime() function #include <stdio.h> #include <time.h> #define UTC (0) #define ART (-3) int main() { // object time_t current_time; // pointer struct tm* ptime; // use time function time(¤t_time); // print the current time ptime = gmtime(¤t_time); printf("Current time:\n"); printf("Monrovia ( Liberia ) :%2d:%02d:%02d\n", (ptime->tm_hour + UTC) % 24, ptime->tm_min, ptime->tm_sec); printf("Buenos Aires ( Argentina ) :%2d:%02d:%02d\n", (ptime->tm_hour + ART) % 24, ptime->tm_min, ptime->tm_sec); return 0; } OutputCurrent time: Monrovia ( Liberia ) :11:45:36 Buenos Aires ( Argentina ) : 8:45:36 Create Quiz Comment A AmanSrivastava1 Follow 2 Improve A AmanSrivastava1 Follow 2 Improve Article Tags : C Language CPP-Functions C-Library Explore C BasicsC Language Introduction6 min readIdentifiers in C3 min readKeywords in C2 min readVariables in C4 min readData Types in C3 min readOperators in C8 min readDecision Making in C (if , if..else, Nested if, if-else-if )7 min readLoops in C6 min readFunctions in C5 min readArrays & StringsArrays in C4 min readStrings in C5 min readPointers and StructuresPointers in C7 min readFunction Pointer in C5 min readUnions in C3 min readEnumeration (or enum) in C5 min readStructure Member Alignment, Padding and Data Packing8 min readMemory ManagementMemory Layout of C Programs5 min readDynamic Memory Allocation in C7 min readWhat is Memory Leak? How can we avoid?2 min readFile & Error HandlingFile Handling in C11 min readRead/Write Structure From/to a File in C3 min readError Handling in C8 min readUsing goto for Exception Handling in C4 min readError Handling During File Operations in C5 min readAdvanced ConceptsVariadic Functions in C5 min readSignals in C language5 min readSocket Programming in C8 min read_Generics Keyword in C3 min readMultithreading in C9 min read Like