开发者

__time32_t time precision?

I'm using an api which uses two __time32_t objects to open a cursor to a database, specifying the start and end time to query over.

Does __time32_t have sub-second (millisecond) time precision? The MSDN is somewhat unclear.

The time32_t object I have does this:

currentET-=.1;

Which I expected to give me the time inside of currentET minus 10 milliseconds, but all it does is subtract a full second, as if I d开发者_StackOverflow中文版id this:

currentET-=1;

How can I get this precision back into the time32_t object?


__time32_t is just an integral type - it doesn't have any particular resolution beyond being integral. The typical functions __time32_t is used with do have 1-second resolution though.


Here's an example of something that generates a sub second accurate time output. Forgive the use of the TCHAR macros... old code base.

void getCurrTimeString(TCHAR* mytime)
{
    _timeb myTime;
    struct tm * timeinfo;

    _ftime64_s( &myTime );
    time_t rawtime = myTime.time;
    unsigned short myMillis = myTime.millitm;
    timeinfo = localtime ( &rawtime );
    _stprintf(mytime,_T("%d-%02d-%02dT%02d:%02d:%02d.%03d"),
        (1900+timeinfo->tm_year),
        (timeinfo->tm_mon+1),
        timeinfo->tm_mday,
        timeinfo->tm_hour,
        timeinfo->tm_min,
        timeinfo->tm_sec,
        myMillis);
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜