2024年3月9日发(作者:)
linux 系统时间函数
Linux系统提供了许多用于操作系统时间和日期的函数。以下是一些常见的函数。
1. time_t time(time_t *t):返回当前时间的时间戳,以自1970年1月1日
00:00:00 UTC以来的秒数为单位。如果t不为空,则时间戳也被存储在t指向
的位置。
2. struct tm *localtime(const time_t *timep):将给定的时间戳转换为本地时
间。返回一个指向tm结构的指针,其中包含本地时间的小时,分钟,秒等。
3. struct tm *gmtime(const time_t *timep):将给定的时间戳转换为GMT时
间(格林威治标准时间)。返回一个指向tm结构的指针,其中包含GMT时间的
小时,分钟,秒等。
4. time_t mktime(struct tm *tm):将给定的tm结构(其中包含小时,分钟,
秒等)转换为对应的时间戳。
5. char *ctime(const time_t *timep):将给定的时间戳转换为一个字符串,表
示为"Day Mon dd hh:mm:ss yyyy"的格式。
6. int gettimeofday(struct timeval *tv, struct timezone *tz):获取当前时间
和时区。返回一个表示微秒级别的时间戳,并将tv指向的结构中的秒数和微秒
数及tz指向的结构中的本地时区信息填充。


发布评论