- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个函数,我希望该函数在运行一定毫秒数后停止运行。这个函数可以工作几秒钟,但我想测试它几毫秒。我该怎么做呢?如果我设置消除= 1,它对应于1秒。如何设置消除 = 5 毫秒?
功能:
void clsfy_proc(S_SNR_TARGET_SET pSonarTargetSet, unsigned char *target_num, time_t eliminate)
{
// get timing
time_t _start = time(NULL);
time_t _end = _start + eliminate;
int _eliminate = 0;
//some code
time_t start = time(NULL);
time_t end = start + eliminate;
for(_tidx = 0; _tidx < pSonarTargetSet[_i].num; _tidx++) {
// check timing
time_t _current = time(NULL);
if (_current > _end) {
printf("clsfy_proc(1), Eliminate due to timeout\n");
_eliminate = 1;
break;
}
//some code
if (_eliminate == 1)
break;
}
//some code
}
最佳答案
time_t
是绝对时间,表示为自 UNIX 纪元(格林尼治标准时间午夜,1970 年 1 月 1 日)以来的整数秒数。它作为时间点的明确且易于使用的表示非常有用。
clock_t
是时间的相对测量,由某个时间点以来的整数个时钟滴答表示(可能是计算机的启动,但不能保证,因为它可能经常翻转)。每秒有 CLOCKS_PER_SEC 时钟滴答数;该常量的值在不同的操作系统之间可能有所不同。它有时用于计时目的,但由于其分辨率相对较低,因此不太擅长。
clock_t
的一个小例子:
#include <time.h>
#include <stdio.h>
int main () {
clock_t start_t, end_t, total_t;
int i;
start_t = clock();
printf("Starting of the program, start_t = %ld\n", start_t);
for(i=0; i< 10000000; i++) { }
end_t = clock();
printf("End of the big loop, end_t = %ld\n", end_t);
total_t = (double)(end_t - start_t) / CLOCKS_PER_SEC;
printf("Total time taken by CPU: %f\n", total_t );
return(0);
}
关于c - 将 time_t 设置为毫秒,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52869470/
我想将日期时间字符串保存到 time_t,然后将其转换回完全原始的字符串。 但是下面的代码会输出"2016-04-25_10:10:05" 并且通过更改 date_str,输出中的小时将不正确。 如果
我有两个 time_t 变量:timeA 和 timeB。 我想做的是检查 timeA 是否与 timeB 相同。但是,我知道在某些情况下它们不会完全相同,两者之间可能会有 1 或 2 秒的差异,所以
我正在尝试编写函数来帮助自己轻松地将 string 转换为 time_t 并将 time_t 转换为 string。然而,它总是给我错误的一年和一个错误的时间。怎么了? 我需要它独立于操作系统! 例如
time_t raw_time = time(NULL); tm* current_time = localtime(&raw_time); 我自己得到了答案......我完全搞砸了警告。无论如何谢谢
我的 time_t 值为 1530173696,代表 2018 年 6 月 28 日,星期四 8:14:56 AM。 我想将时间向下舍入到最接近的小时。具体来说,向下到 1530172800,代表 T
我正在开发嵌入式系统。我们的平台是 32 位,因此 time_t 大小是 32 位。 现在我想将一个结构作为 char 数组发送到 Windows 7 计算机。我的结构体的字段之一是time_t。我无
time_t 这是依赖于平台的类型。我发现 difftime 以秒为单位返回差异,但我没有找到无需任何转换即可进行简单减法的函数。我怎么知道标准不保证在整个时间连续体中始终如一,并且没有说明有关 ti
我正在尝试转换 static char bufferTR[] = "1645"; 像这样的事情...... struct tm *tick_time = localtime(&temp); 在此函数中
在我当前的项目中,我有一个 C 结构来保存时间戳,如下所示: struct timestamp { uint16_t year; uint8_t month; uint8_t day
我有从 2004 年到特定日期的毫秒数。我想将其转换为 time_t 以使用 ctime() 显示它? 也许还有另一种方法可以通过这个毫秒时间戳来可视化日期,有人有吗? 最佳答案 假设“从 2004
我应该如何修改此代码以在每 00:00AM 打印(“Its Midnight”)? #include #include int main(void) { struct tm * localti
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 6 年前。 Improve th
我是 C 编程新手,我需要一些帮助来完成一个简单的任务。 所以我有这个功能: char *time2str(time_t time) { static_char *str_fmt = "%0
我正在使用处理 time_t 的 API。现在我也有一个来自 API 的结果,它也在 time_t 中检索数据,但问题是第一个只需要日期、小时和分钟,但我检索的数据包括秒,我如何从数据中删除秒>
我正在尝试将“Tue Feb 13 00:26:36 2018”转换为 time_t,我该怎么做,我尝试寻找一个函数但找不到。这是使用非托管 C++。 最佳答案 如果你使用的是 C++11,你可以这样
我有一个 double 的纪元,需要传入一个需要 time_t 的函数。如何将 double 中的纪元转换为 time_t?我在 Linux 上使用 C++ 代码。谢谢。 最佳答案 如果你在 doub
根据 http://www.cplusplus.com/reference/clibrary/ctime/time_t/ time_t 是自 1970 年 1 月 1 日午夜 UTC 以来的秒数。因此
我试图找出时间将溢出 time_t 值的日期 #include #include #include main(){ time_t now,end; now=time(NU
如果我有这个字符串: 2011-10-08T07:07:09Z 是否有可能从中获取time_t?如果可以,如何实现? 最佳答案 是的,是的。首先,使用 strptime(3) 将其转换为 segmen
我不明白为什么这会抛出undefined reference to `floor'”: double curr_time = (double)time(NULL); return floor(curr
我是一名优秀的程序员,十分优秀!