locked
Get timestamp in millisecond RRS feed

  • Question

  • Hi,
    How can I do to get the timestamp in millisecond?

    :)
    Thursday, July 30, 2009 9:21 AM

Answers

  • Could you share information on your end goal?  It may help in identifying a timer that fits your needs?

    QueryPerformanceTimer() can be used to read a high performance timer (whose frequency can be read with QueryPerformanceFrequency). While these functions immediatly come to mind I don't know if they are well suited for your goal since I don't know what your goal it.


    Joel Ivory Johnson
    Thursday, July 30, 2009 9:11 PM
  • My application is too low.

    The goal is see why and where is low.

    With timestamp I can see where my application is slow.

    I done:

    unsigned int getMillisecond() 
    { 
         __int64 freq, time, time_milli;
         unsigned int milliseconds;
    
         // The QueryPerformanceFrequency function retrieves the   frequency of the high-resolution performance counter, if one exists. The frequency cannot change while the system is running
         QueryPerformanceFrequency((LARGE_INTEGER*)&freq);  
     
           // The QueryPerformanceCounter function retrieves the current  value of the high-resolution performance counter
         QueryPerformanceCounter((LARGE_INTEGER*)&time);
        
         time_milli = ((time) * 1000) / freq;
         milliseconds = (unsigned int)(time_milli & 0xffffffff);
         return milliseconds;
    } 
    
    


    Could it be a good solution?

    • Marked as answer by chiara1990 Saturday, August 8, 2009 7:09 AM
    Friday, July 31, 2009 7:54 AM

All replies

  • GetTickCount() if you want to use it as a timer
    http://msdn.microsoft.com/en-us/library/aa915056.aspx

    or

    GetSystemTime() if you want the actual time of day down to the millisecond
    http://msdn.microsoft.com/en-us/library/aa908972.aspx

    -PaulH
    Thursday, July 30, 2009 5:00 PM
  • GetSystemTime() if you want the actual time of day down to the millisecond

    Except the ms count is always 0 on the mobiles.  GetTickCount() is not useful in that it's out of sync with wall time.  what I do is simply increment a counter each time I get a time if I need more than 1-sec precision.  The counter could be based on the rest of the time being the same as last time, or a 32-bit free-running counter.  maxnix really (you could even use the tick count).  Unless you need an accurate ms count.
    • Proposed as answer by Pigs Man Thursday, July 30, 2009 8:54 PM
    Thursday, July 30, 2009 8:54 PM
  • Could you share information on your end goal?  It may help in identifying a timer that fits your needs?

    QueryPerformanceTimer() can be used to read a high performance timer (whose frequency can be read with QueryPerformanceFrequency). While these functions immediatly come to mind I don't know if they are well suited for your goal since I don't know what your goal it.


    Joel Ivory Johnson
    Thursday, July 30, 2009 9:11 PM
  • My application is too low.

    The goal is see why and where is low.

    With timestamp I can see where my application is slow.

    I done:

    unsigned int getMillisecond() 
    { 
         __int64 freq, time, time_milli;
         unsigned int milliseconds;
    
         // The QueryPerformanceFrequency function retrieves the   frequency of the high-resolution performance counter, if one exists. The frequency cannot change while the system is running
         QueryPerformanceFrequency((LARGE_INTEGER*)&freq);  
     
           // The QueryPerformanceCounter function retrieves the current  value of the high-resolution performance counter
         QueryPerformanceCounter((LARGE_INTEGER*)&time);
        
         time_milli = ((time) * 1000) / freq;
         milliseconds = (unsigned int)(time_milli & 0xffffffff);
         return milliseconds;
    } 
    
    


    Could it be a good solution?

    • Marked as answer by chiara1990 Saturday, August 8, 2009 7:09 AM
    Friday, July 31, 2009 7:54 AM