开发者

Regarding getting time in milliseconds

I am working on logger using C language on QNX platform using Momnetics to print time in following format

2010-11-02 14:45:15.000

I able to get date, hour, minutes, and seconds using

 time(&timeSpec);开发者_如何学JAVA
 struct tm gmt;
 int iSysTimeSec = timeSpec;
 gmtime_r((time_t *)&iSysTimeSec, &gmt);
 sprintf(&MsgStamp[0], SYS_MSG_STAMP_PRINTF_FORMAT, gmt.tm_year+1900, gmt.tm_mon + 1, gmt.tm_mday, gmt.tm_hour, gmt.tm_min, gmt.tm_sec, iSysTimeMs );

Question is how do i get milliseconds granularity using QNX Momentics.

I tried to get granulaity for milliseconds using QNX specific int iSysTimeMs = ( (ClockCycles () * 1000) / SYSPAGE_ENTRY(qtime)->cycles_per_sec ) % 1000;

but i want to do this POSIX way so that it is portable. How do we do this?

Thanks! Venkata


In QNX6 You can use the clock_gettime to have the max granularity allowed by system.

struct timespec start;
clock_gettime( CLOCK_REALTIME, &start);


The gettimeofday() system call will return a structure holding the current Unix time in seconds and the number of microseconds belonging to the current second.

To get the total number of microseconds:

struct timeval tv;
gettimeofday(&tv, NULL);
u_int64_t now = tv.tv_sec * 1000000ULL + tv.tv_usec;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜