Which header file is required to work with date and time in C?
Analysis & Theory
`time.h` provides functions like `time()`, `localtime()`, and `strftime()` for handling date and time.
Which function returns the current calendar time?
Analysis & Theory
`time(NULL)` returns the current time as `time_t` (seconds since epoch).
Which function converts `time_t` to a `tm` struct in **local time**?
Analysis & Theory
`localtime()` converts a `time_t` value into a `tm` struct adjusted to local time zone.
What does `struct tm` represent in C?
C
Broken-down calendar time
Analysis & Theory
`struct tm` holds broken-down time (year, month, day, hour, etc.).
Which function can format a `tm` structure into a string?
Analysis & Theory
`strftime()` formats time in a buffer based on a format string (like `%Y-%m-%d`).
Which function returns the number of seconds between two `time_t` values?
Analysis & Theory
`difftime(t1, t2)` returns the difference in seconds between two `time_t` values.
What is the output type of `time()` function?
Analysis & Theory
`time()` returns a value of type `time_t`.
What does this code do?
```c
printf("%s", ctime(&t));
```
B
Prints formatted time string
Analysis & Theory
`ctime()` converts `time_t` into a formatted string like `Tue Jul 1 15:26:40 2025`.
What is the epoch time (used by `time_t`) based on?
Analysis & Theory
`time_t` stores time as seconds since **Jan 1, 1970, 00:00:00 UTC** (the Unix epoch).
Which of the following is the correct way to get current year from `struct tm`?
Analysis & Theory
The `tm_year` value is years since 1900, so you must add 1900 to get the actual year.