C wiki - struct tm

K

Kenneth Brody

http://alien.dowling.edu/~rohit/wiki/index.php/C_Programming#Standard_Library

Q: How are months of a year numbered in C?

Answer makes reference to "the Standard specifies struct tm". Does the
C standard actually define struct tm, or is it Posix that defines it?

--
+-------------------------+--------------------+-----------------------------+
| Kenneth J. Brody | www.hvcomputer.com | |
| kenbrody/at\spamcop.net | www.fptech.com | #include <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------------+
Don't e-mail me at: <mailto:[email protected]>
 
B

Ben Pfaff

Kenneth Brody said:
Q: How are months of a year numbered in C?

Answer makes reference to "the Standard specifies struct tm". Does the
C standard actually define struct tm, or is it Posix that defines it?

It is in the C standard. See e.g. C99 7.23.1 paragraphs 3 and 4.
 
S

Simon Biber

Kenneth said:
http://alien.dowling.edu/~rohit/wiki/index.php/C_Programming#Standard_Library

Q: How are months of a year numbered in C?

Answer makes reference to "the Standard specifies struct tm". Does the
C standard actually define struct tm, or is it Posix that defines it?

The C standard defines struct tm as follows:

7.23 Date and time <time.h>
7.23.1 Components of Time
....
4 The range and precision of times representable in clock_t and
time_t are implementation-defined. The tm structure shall
contain at least the following members, in any order. The
semantics of the members and their normal ranges are expressed
in the comments.

int tm_sec; // seconds after the minute — [0, 60]
int tm_min; // minutes after the hour — [0, 59]
int tm_hour; // hours since midnight — [0, 23]
int tm_mday; // day of the month — [1, 31]
int tm_mon; // months since January — [0, 11]
int tm_year; // years since 1900
int tm_wday; // days since Sunday — [0, 6]
int tm_yday; // days since January 1 — [0, 365]
int tm_isdst; // Daylight Saving Time flag

The value of tm_isdst is positive if Daylight Saving Time is
in effect, zero if Daylight Saving Time is not in effect, and
negative if the information is not available.
 
S

Spiro Trikaliotis

Hello,

Simon Biber said:
int tm_sec; // seconds after the minute — [0, 60]
int tm_min; // minutes after the hour — [0, 59]

Is tm_sec really from 0 to 60 (including)? I do not see the sense of it
in contrast to all the others (0.59 for minutes, 0..23 for hour, ...)

What is the rationale behind this? Does it have anything to do with leap
seconds?

Curious,
Spiro.
 
S

Stephen Hildrey

Spiro said:
Is tm_sec really from 0 to 60 (including)? I do not see the sense of it
in contrast to all the others (0.59 for minutes, 0..23 for hour, ...)

What is the rationale behind this? Does it have anything to do with leap
seconds?

Yes.
 
D

Dik T. Winter

> Simon Biber said:
> > int tm_sec; // seconds after the minute — [0, 60]
> > int tm_min; // minutes after the hour — [0, 59]
>
> Is tm_sec really from 0 to 60 (including)? I do not see the sense of it
> in contrast to all the others (0.59 for minutes, 0..23 for hour, ...)
>
> What is the rationale behind this? Does it have anything to do with leap
> seconds?

It has everything to do with leap seconds.
 
C

CBFalconer

Spiro said:
Simon Biber said:
int tm_sec; // seconds after the minute — [0, 60]
int tm_min; // minutes after the hour — [0, 59]

Is tm_sec really from 0 to 60 (including)? I do not see the sense
of it in contrast to all the others (0.59 for minutes, 0..23 for
hour, ...)

What is the rationale behind this? Does it have anything to do
with leap seconds?

Precisely. i.e. yes.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top