如何在vxworks上的c / c ++中获取带有日期的系统时间(以毫秒为单位)

时间:2017-01-30 15:29:20

标签: c++ vxworks

我在下面尝试过以毫秒为单位获取日期的系统时间。 它在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;
}

2 个答案:

答案 0 :(得分:2)

您可以查看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 */
}

答案 1 :(得分:-1)

尝试tickget()

(1000 * tickGet() / sysClkRateGet(1000))将以ms为单位给出当前时间。根据这个source

相关问题