C gmtime() function
C gmtime() function - Convert a time value to a broken-down UTC time
Syntax:
struct tm *gmtime(const time_t *timer)
The gmtime() function is used to break down the time value, in seconds, and stores it in a tm structure, defined in <time.h>.
The fields of the tm structure include:
tm_sec | Seconds (0-61) |
tm_min | Minutes (0-59) |
tm_hour | Hours (0-23) |
tm_mday | Day of month (1-31) |
tm_mon | Month (0-11; January = 0) |
tm_year | Year (current year minus 1900) |
tm_wday | Day of week (0-6; Sunday = 0) |
tm_yday | Day of year (0-365; January 1 = 0) |
tm_isdst | Zero if daylight saving time is not in effect; positive if daylight saving time is in effect; negative if the information is not available. |
Parameters:
Name | Description | Required /Optional |
---|---|---|
timeptr | This is the pointer to a time_t value representing a calendar time. | Required |
Return value from gmtime()
- The gmtime() function returns a pointer to the resulting tm structure.
Example: gmtime() function
The following example displays the Coordinated Universal Time.
#include <stdio.h>
#include <time.h>
int main(void)
{
time_t ltime;
time(<ime);
printf ("Coordinated Universal Time is %s\n",
asctime(gmtime(<ime)));
}
Output:
Coordinated Universal Time is Tue Dec 20 04:57:46 2022
C Programming Code Editor:
Previous C Programming: C difftime()
Next C Programming: C localtime()
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://w3resource.com/c-programming/time/c-gmtime.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics