关于获取以毫秒为单位的时间
我正在 QNX 平台上使用 C 语言开发记录器,使用 Momnetics 以以下格式打印时间
2010-11-02 14:45:15.000
我能够使用获取日期、小时、分钟和秒
time(&timeSpec);
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 );
问题是如何获得毫秒粒度使用 QNX Momentics。
我尝试使用 QNX 特定的方法获得毫秒级的粒度 int iSysTimeMs = ( (ClockCycles () * 1000) / SYSPAGE_ENTRY(qtime)->cycles_per_sec ) % 1000;
但我想采用这种 POSIX 方式,以便它是可移植的。我们该怎么做?
谢谢! 文卡塔
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);
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在QNX6中,您可以使用clock_gettime来获得最大粒度
系统允许。
In QNX6 You can use the clock_gettime to have the max granularity
allowed by system.
gettimeofday() 系统调用将返回一个结构,其中保存当前 Unix 时间(以秒为单位)以及属于当前秒的微秒数。
要获取总微秒数:
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: