time_t 是以什么为单位?

踏实每一步 2010-09-27 09:27:58
秒还是毫秒
...全文
4918 11 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
FengRider 2010-09-27
  • 打赏
  • 举报
回复
并不是不可以把time_t看成别的时间单位,但如果这样做,那些已经固定的返回值或者参数为time_t类型的函数将失去原有的意义。
之所以将time_t看成是某一时刻到另一时刻的秒数,就是为了赋于它一个时间段的概念,如果非要抛弃这个概念,而要将其打回原型,何必再设一个time_t类型,直接用long不就得了。
FengRider 2010-09-27
  • 打赏
  • 举报
回复
time_t实际上是长整型的数,表示从一个时间点(一般是1970年1月1日0时0分0秒)到某一时刻时的秒数(即日历时间)。对time_t数据类型的值来说,它所表示的时间不能晚于2038年1月18日19时14分07秒。
至于6楼和7楼所说,那是把time_t当成一个long型整数来看了,而没有把time_t看成一个时间。
请6楼的仔细看看GetTickCount函数的定义先:
GetTickCount返回(retrieve)从操作系统启动到现在所经过(elapsed)的毫秒数,它的返回值是DWORD。
众所周知,微软在某些地方用DWORD来代替long。所以即使你用time_t t2=GetTickGount()也不会报错,但此时你根本就没将time_t看成一个时间,而只是一个普通的长整型的数而已,将此数独自认定的一个时间值,并不是大家公认的时间数。
mujiok2003 2010-09-27
  • 打赏
  • 举报
回复
Time type

Type capable of representing times and support arithmetical operations.

This type is returned by the time function and is used as parameter by some other functions of the <ctime> header.

It is almost universally expected to be an integral value representing the number of seconds elapsed since 00:00 hours, Jan 1, 1970 UTC. This is due to historical reasons, since it corresponds to a unix timestamp, but is widely implemented in C libraries across all platforms.

time_t 其实就是一个整型而已。
GARY 2010-09-27
  • 打赏
  • 举报
回复
额。。。
原来如此。
楼主别被1. 2. 3. 4. 5.楼误导了。
。。。
Rainqin123 2010-09-27
  • 打赏
  • 举报
回复
time_t is a Standard Type

具体问题具体分析......毫秒也对,秒也对,纳秒也对....
xiaohuh421 2010-09-27
  • 打赏
  • 举报
回复
time_t 大家不要搞错了,这只是一个数据类型吗,和 秒 毫秒 不相干吧.
typedef long time_t;//在time.h中定义.

time_t t1=time(NULL);//这样得到的就是秒



time_t t2=GetTickCount();//这样得到的就是毫秒
llllllllllllleon 2010-09-27
  • 打赏
  • 举报
回复 1
是秒。
GARY 2010-09-27
  • 打赏
  • 举报
回复
看了一下,应该是(秒)。
找个佐证:(from msdn)
---------------------
Get the system time.
time_t time(
time_t *timer
);
Return the time as seconds elapsed since midnight,
January 1, 1970. There is no error return.

---------------------
GARY 2010-09-27
  • 打赏
  • 举报
回复
看了一下,应该是(秒)。
找个佐证:(from msdn)
---------------------
Get the system time.
time_t time(
time_t *timer
);
Return the time as seconds elapsed since midnight,
January 1, 1970. There is no error return.

---------------------


城都042025 2010-09-27
  • 打赏
  • 举报
回复
答案是对的,记得把分给我哦!呵呵……
城都042025 2010-09-27
  • 打赏
  • 举报
回复
time_t的单位是秒。

65,186

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧