Log with timestamps that have millisecond accuracy & resolution in Windows C++
        Posted  
        
            by 
                Psychic
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Psychic
        
        
        
        Published on 2010-12-31T12:51:17Z
        Indexed on 
            2010/12/31
            12:53 UTC
        
        
        Read the original article
        Hit count: 312
        
I'm aware that for timing accuracy, functions like timeGetTime, timeBeginPeriod, QueryPerformanceCounter etc are great, giving both good resolution & accuracy, but only based on time-since-boot, with no direct link to clock time.
However, I don't want to time events as such. I want to be able to produce an exact timestamp (local time) so that I can display it in a log file, eg 31-12-2010 12:38:35.345, for each entry made. (I need the millisecond accuracy)
The standard Windows time functions, like GetLocalTime, whilst they give millisecond values, don't have millisecond resolution, depending on the OS running. I'm using XP, so I can't expect much better than about a 15ms resolution.
What I need is a way to get the best of both worlds, without creating a large overhead to get the required output. Overly large methods/calculations would mean that the logger would start to eat up too much time during its operation.
What would be the best/simplest way to do this?
© Stack Overflow or respective owner