The C language has a time function that I personally find awkward. Even if it is difficult to handle, I will obey quietly because I do not have the skill to make more things, but I will write the connection because it was hard to remember. ..
Maybe we will increase the Windows edition, clock, timer, etc.?
tl;dr(too long didn't read)
A type that indicates the number of seconds that have elapsed since 0:00:00 (UTC) on January 1, 1970. In other words, I don't know the date or time as it is </ font>.
Structure definition
#include <time.h>
time_t time(time_t *t);
C language standard time acquisition function. There are two ways to use it.
time()Notation
time_t current_time;
time(¤t_time); //If you give a buffer, it will be put in there
or
time_t current_time = time(NULL); //Return value is OK
Use when you want more detailed date information.
It was a big success when I put the date on the log.
You can also convert struct timespec
and struct tm
within the Linux Kernel. ..
Definition
struct tm {
int tm_sec; /*Seconds(0-60) */
int tm_min; /*Minutes(0-59) */
int tm_hour; /*time(0-23) */
int tm_mday; /*Date in the month(1-31) */
int tm_mon; /*Month(0-11) */
int tm_year; /*Year- 1900 */
int tm_wday; /*Day of the week(0-6,Sunday= 0) */
int tm_yday; /*Total date within the year(0-365,January 1= 0) */
int tm_isdst; /*Daylight saving time*/
};
It is used when you want to express the time in characters.
Times of Day->Character notation
#include <time.h>
char *ctime(const time_t *timep); // Thread unsafe
char *ctime_r(const time_t *timep, char *buf); // Thread safe
-** C language standard : ctime ()
Since it returns a pointer to the internal memory, it has a thread unsafe problem that the recipient changes when the internal memory is rewritten.
- POSIX only **: ctime_r ()
Since the output buffer is requested from the user side, the value is guaranteed even if it is rewritten internally.
It's a hassle to convert from the time_t type, and am I the only one who thinks it's okay to have a function that returns the struct tm
of the current time?
I'm sure I just don't know.
Conversion function
#include <time.h>
// GMT
struct tm *gmtime(const time_t *timep); // Thread unsafe
struct tm *gmtime_r(const time_t *timep, struct tm *result); // Thread safe
//Local time
struct tm *localtime(const time_t *timep); // Thread unsafe
struct tm *localtime_r(const time_t *timep, struct tm *result); // Thread safe
Conversion function
#include <stdio.h>
size_t strftime(char *s, size_t max, const char *format, const struct tm *tm);
If you want to output it, you may put it in the printf
function separately.