Skip to Content
C in a Nutshell
book

C in a Nutshell

by Peter Prinz, Tony Crawford
December 2005
Beginner to intermediate
618 pages
20h 19m
English
O'Reilly Media, Inc.
Content preview from C in a Nutshell

Name

gmtime

Synopsis

Converts a timer value into a year, month, day, hour, minute, second, etc.

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

The gmtime() function converts a numeric time value (usually a number of seconds since January 1, 1970, but not necessarily) into the equivalent date and time structure in Coordinated Universal Time (UTC, formerly called Greenwich Mean Time; hence the function’s name). To obtain similar values for the local time, use the function localtime().

The function’s argument is not the number of seconds itself, but a pointer to that value. Both the structure type struct tm and the arithmetic type time_t are defined in the header file time.h.

The tm structure is defined as follows:

struct tm {
  int tm_sec;            /* Seconds since the full minute: 0 to 60 */
  int tm_min;            /* Minutes since the full hour:   0 to 59 */
  int tm_hour;           /* Hours since midnight:          0 to 23 */
  int tm_mday;           /* Day of the month:     1 to  31 */
  int tm_mon;            /* Months since January: 0 to  11 */
  int tm_year;           /* Years since 1900               */
  int tm_wday;           /* Days since Sunday:    0 to   6 */
  int tm_yday;           /* Days since Jan. 1:    0 to 365 */
  int tm_isdst;          /* Flag for Daylight Savings Time:
                            greater than 0 if time is DST;
                            equal to 0 if time is not DST;
                            less than 0 if unknown.        */
};

The argument most often passed to gmtime() is the current time, obtained as a number with type time_t by calling the function time(). The type time_t is defined in time.h, usually as equivalent to long or unsigned long.

Example

The following program ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

C in a Nutshell, 2nd Edition

C in a Nutshell, 2nd Edition

Peter Prinz, Tony Crawford
Smaller C

Smaller C

Marc Loy
C Pocket Reference

C Pocket Reference

Peter Prinz, Ulla Kirch-Prinz
Extreme C

Extreme C

Kamran Amini

Publisher Resources

ISBN: 0596006977Errata Page