Unix的时间值

Unix的时间值
Unix纪元:1970年1月1日00:00:00
国际标准时间:本初子午线(地理经度起点)格林尼治天文台原址时间,又称格林尼治时间,UTC(Coordinated Universal Time,协调世界时)。
日历时间:Unix纪元以来UTC所经过的秒数累计值。系统基本数据类型time_t
进程时间:即CPU时间,度量进程使用CPU资源,单位是时间滴答。系统基本数据类型clock_t
时钟时间:墙上时间,进程运行时间总量。它与系统中同时运行的进程数有关。
用户CPU时间:执行用户指令所用的时间
系统CPU时间:执行内核程序所经历的时间。
CPU时间:用户CPU时间和系统CPU时间之和。time -p 程序
#include <time.h>
time_t time(time_t *calptr);//返回当前时间和日期

struct timeval
{
	time_t tv_sev;/* seconds */
	long tv_usec;/* microseconds */
}
#include <sys/time.h>
int gettimeofday(struct timeval *restrict tp,void *restrict tzp);//tzp=NULL(必须)

struct tm
{
	int tm_sec;[0-60]
	int tm_min;[0-59]
	int tm_hour;[0-23]
	int tm_mday;[1-31]
	int tm_mon;[0-11]
	int tm_year;//从1900年经历的年数
	int tm_wday;//从星期日经历的天数
	int tm_yday;//从1月1日经历的天数
	int tm_isdst;//夏时制标志,夏时制生效正,非夏时制0,信息不可用负
}

#include<time.h>
struct tm *gmtime(const time_t *calptr);//将日历时间转换成国际标准时间的年月日时分秒周
struct tm *localtime(const time_t *calptr);//将日历时间转换成本地时间(考虑本地时区和夏时制)
time_t mktime(struct tm *tmptr);//以本地时间的年月日等作为参数,将其转换成time_t
char *asctime(const tm *tmptr);//返回26字节字符串
char *ctime(const time_t *calptr);//返回26字节字符串
/*复杂函数类似于printf,格式化时间结果放在长度为maxsize个字符的buf数组中,返回值为buf字符数,
format参数控制时间值格式,转换说明查表*/
size_t strftime(char *restrict buf,size_t maxsize,
		const char *restrict format,
		const struct tm *restrict tmptr);
环境变量TZ,保存当前时区,例如:TZ=EST5EDT
夏时令(summer time;daylight saving time-DST)

以下函数变成获得进程的墙上时间和用户CPU时间和系统CPU时间
#include <sys/times.h>
clock_t times(struct tms *buf);//返回墙上时间滴答数,前后做差值,函数填写buf
struct tms
{
	clock_t tms_utime;//用户CPU时间
	clock_t tms_stime;//系统CPU时间
	clock_t tms_cutime;//已终止的子进程用户CPU时间
	clock_t tms_cstime;//已终止的子进程系统CPU时间
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值