在Linux中玩转时间管理:RTC、定时延时、闹钟设置与时间格式转换指南
最编程
2024-02-12 07:29:53
...
#include <time.h>
struct tm {
int tm_sec; /* seconds */
int tm_min; /* minutes */
int tm_hour; /* hours */
int tm_mday; /* day of the month */
int tm_mon; /* month */
int tm_year; /* year */
int tm_wday; /* day of the week */
int tm_yday; /* day in the year */
int tm_isdst; /* daylight saving time */
};
char *asctime(const struct tm *tm); //内部有一个全局空间存放转换的时间
char *asctime_r(const struct tm *tm, char *buf); //用户可以指定自己的空间
函数功能: 将tm时间结构体里的时间转为字符串格式返回(指针返回).
char *ctime(const time_t *timep);
char *ctime_r(const time_t *timep, char *buf);
函数功能: 将秒单位的时间转为字符串格式返回.
struct tm *gmtime(const time_t *timep);
struct tm *gmtime_r(const time_t *timep, struct tm *result);
函数功能: 将秒单位的时间转为格林威治时间返回---使用tm结构体。
struct tm *localtime(const time_t *timep);
struct tm *localtime_r(const time_t *timep, struct tm *result);
函数功能: 将秒单位的时间转为本地时间返回.---使用tm结构体
time_t mktime(struct tm *tm);
函数功能: 将tm结构体时间转为秒单位返回.
time_t time(time_t *t);
函数功能:如果形参填NULL就表示获取当期系统的秒单位时间.
size_t strftime(char *s, size_t max, const char *format,
const struct tm *tm);
函数功能: 将tm结构体的时间按照指定的格式转成字符串返回.
const char *format 格式有以下格式可以填:
%H 小时(以 00-23 来表示)
%M 分钟(以 00-59 来表示)
%S 秒(以本地的惯用法来表示)
%Y 年份(以四位数来表示)
%m 月份(以 01-12 来表示)
%d 日期(以 01-31 来表示)。
上一篇: 原生js设置rem
下一篇: REM睡眠的基础知识详解与入门介绍