Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想知道收到消息时的时间戳。我应该检查收到最后一条消息是否已经 N 秒。我正在使用time_t. 我把当前时间是这样的:time (& myTime);
time_t
time (& myTime);
我如何检查他们是否花费了超过 N 秒?
有没有办法知道总 time_t 的秒数(时间戳)?
您询问 a 的“秒数” time_t。这将是绝对时间。您可能想要使用localtime()小时/分钟/秒、日/月/年的形式使用或某些此类功能对其进行格式化。
localtime()
如果您想知道自上一个事件以来的时间,您应该简单地保存time_t来自该事件的时间,然后使用类似的语句if (difftime(thisevent_time, lastevent_time) > max_seconds)来处理它。
if (difftime(thisevent_time, lastevent_time) > max_seconds)