我在下面尝试获取系统时间和日期(以毫秒为单位)。 在Linux平台上工作正常,但在VXworks上无法工作。我需要类似的 vxworks 解决方案。
#include <sys/time.h> /* It seems this is not available on vxworks */
#include <iostream>
using namespace std;
int main()
{
struct timeval tp;
gettimeofday(&tp, NULL);
unsigned long int ms = tp.tv_sec * 1000 + tp.tv_usec / 1000;
cout<<ms
return 0;
}
最佳答案
您可以看看 clockLib 的功能.
下面的代码应该可以解决问题:
#include <vxworks.h>
#include <timers.h>
struct timespec t;
if (clock_gettime(CLOCK_REALTIME, &t) == OK)
{
/* t.tv_usec and t.tv_sec are valid */
}
关于c++ - 如何在vxworks上的c/c++中获取带有日期的系统时间(以毫秒为单位),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41939606/