Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

c

What is tm in C?

Samia Ishaque

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Answers Code

struct tm is a structure defined in the time.h header file in C language. Each of the member objects of struct tm contains the time and date stored on a machine.

Below is a table that outlines what each member of the struct holds. The Daylight Saving Time flag is positive if it is daylight saving time, negative if it is unknown, and 0 if it is not daylight saving time. All the members are of type int.

Members of Struct

Member


tm_sec

seconds passed since last minute

tm_min

minutes passed since hour

tm_hour

hours passed since midnight

tm_mday

day of the month

tm_mon

months passed since January

tm_year

year passed since 1900

tm_wday

days since Sunday

tm_yday

days since first day of the year

tm_isdst

Daylight Saving Time Flag

Example

The code below illustrates how you can use struct tm to print the calendar time and date. The values for the members of the struct are set to Mon Feb 1 01:01:01 1901 using the (.) operator.

#include<stdio.h>
#include<time.h>
int main() {
struct tm value;
value.tm_sec=1;
value.tm_min=1;
value.tm_hour=1;
value.tm_mday=1;
value.tm_mon=1;
value.tm_year=1;
value.tm_hour=1;
value.tm_wday=1;
value.tm_yday=1;
printf("Time and date: %s", asctime(&value));
return 0;
}

RELATED TAGS

c

CONTRIBUTOR

Samia Ishaque
Copyright ©2022 Educative, Inc. All rights reserved

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Answers Code
Keep Exploring