clock_t,time_t和struct tm有什么区别? [英] What is the difference between clock_t, time_t and struct tm?

查看:308
本文介绍了clock_t,time_t和struct tm有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

clock_t,time_t和struct tm有什么区别?

What is the difference between clock_t, time_t and struct tm?

struct tm 看起来像这样:

struct tm{
int tm_sec;
int tm_min;
int tm_hour;
int tm_mday;
int tm_mon;
int tm_year;
int tm_wday;
int tm_yday;
int tm_isdst;
};

但是 clock_t time_t 看起来如何?

推荐答案

time_t是绝对时间,表示为UNIX纪元(格林尼治标准时间,1970年1月1日)以来的秒数.它可以用作时间点的清晰,易于使用的表示形式.

time_t is an absolute time, represented as the integer number of seconds since the UNIX epoch (midnight GMT, 1 January 1970). It is useful as an unambiguous, easy-to-work-with representation of a point in time.

clock_t是时间的相对度量,由某个时间点以来的整数时钟滴答表示(可能是计算机的启动,但不能保证,因为它可能会经常滚动).每秒有CLOCKS_PER_SEC个时钟滴答;该常数的值在不同的操作系统之间会有所不同,但通常约为100.有时将其用于计时目的,但由于其分辨率相对较低,因此并不是很好. gettimeofdaystruct timeval在计时方面要好得多.

clock_t is a relative measurement of time, represented by an integer number of clock ticks since some point in time (possibly the computer's bootup, but no guarantees, as it may roll over quite often). There are CLOCKS_PER_SEC clock ticks per second; the value of this constant can vary between different operating systems, but it is usually around 100. It is sometimes used for timing purposes, but it is not very good at it due to its relatively low resolution. gettimeofday's struct timeval is much better for timing purposes.

struct tm是日历日期和时间.它可能不代表任何实际时间点(例如,您可以将struct tm表示为2月31日或12月0日).它不包含时区,因此不是绝对的.通常在转换为人类可读的日期和时间表示形式时使用.

struct tm is a calendar date and time. It may not represent any real point in time (e.g, you can have a struct tm that says it is February 31st, or Dodecember 0st). It does not include a time zone, so it is not absolute. It is typically used when converting to or from human-readable representations of the date and time.

这篇关于clock_t,time_t和struct tm有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆