[Linux Programming] Time and Date – 时间与日期

Time & Date

#include <time.h>
time_t time(time_t *tloc);
@返回从1970.1.1开始到当前时间的时间戳(time_t 32-bit int), 单位为s
@tloc: 如果tloc不为nullptr也会被赋值?

double difftime(time_t time1, time_t time2);

// time_t convert to tm
struct tm *gmtime(const time_t timeval); // UTC(Universal Time Coordinated)
@tm: 0-61(leap) | 0-59 | 0-23 | 1-31 | 0(Sunday)-6 | 0-11 | 0-365 | 1900+ | tm_isdst

struct tm *localtime(const time_t *timeval); // local tm

// tm convert to time_t
time_t mktime(struct tm *timeptr);

// tm convert to pretty show
char *asctime(const struct tm *timeptr); // Fri Aug 28 11:41:09 2020, fixed format and 26 characters long.
char *ctime(const time_t *timeval); // = asctime(localtime(timeval))

// more format control
size_t strftime(char *s, size_t maxsize, const char *format, struct tm *timeptr); // tm to format string
char *strptime(const char *buf, const char *format, struct tm *timeptr); // format string to tm

发表评论

电子邮件地址不会被公开。必填项已用 * 标注