Results 1 to 17 of 17

Thread: Current Time with microsecond precision on windows

  1. #1
    Join Date
    Mar 2006
    Location
    somewhere between France & Germany
    Posts
    34
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Question Current Time with microsecond precision on windows

    Hello,

    Does anyone know how, under Windows, I can get the exact current microsecond so that I can display a time with the microsecond precision ?

    Thanks!
    • The Manual said the program required Win95 or better, so I installed Linux.
    • Newton was a pessimist.
    • no Risk! no FuN!

  2. #2
    Join Date
    Mar 2006
    Posts
    9
    Thanks
    2
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Current Time with microsecond precision on windows


  3. #3
    Join Date
    Mar 2006
    Location
    somewhere between France & Germany
    Posts
    34
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Current Time with microsecond precision on windows

    Not at all... It has nothing to do with files and I need microsecond.
    Sorry.
    • The Manual said the program required Win95 or better, so I installed Linux.
    • Newton was a pessimist.
    • no Risk! no FuN!

  4. #4
    Join Date
    Feb 2006
    Location
    New Delhi,India
    Posts
    226
    Thanks
    14
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Current Time with microsecond precision on windows

    Quote Originally Posted by Dwarf007
    Not at all... It has nothing to do with files and I need microsecond.
    Sorry.

    There can be many ways thru which u can get time..

    The include files are :

    ctime.h, time.h, windows.h... they help you in extracting the current system time...

    u can get time in milliseconds.. once you have that, you can extract to microseconds...

    I hope this is what you wanted...

  5. #5
    Join Date
    Mar 2006
    Location
    somewhere between France & Germany
    Posts
    34
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Current Time with microsecond precision on windows

    Quote Originally Posted by Kapil
    u can get time in milliseconds.. once you have that, you can extract to microseconds...
    I need microseconds, milliseconds are not precise enough.
    What do you mean with extract to microseconds ?
    • The Manual said the program required Win95 or better, so I installed Linux.
    • Newton was a pessimist.
    • no Risk! no FuN!

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Current Time with microsecond precision on windows

    Does Windows handle microseconds at all?

  7. #7
    Join Date
    Mar 2006
    Location
    somewhere between France & Germany
    Posts
    34
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Current Time with microsecond precision on windows

    Quote Originally Posted by wysota
    Does Windows handle microseconds at all?
    I heared and read a bit, that using the following Windows API functions : QueryPerformanceFrequency() and QueryPerformanceCounter() it should do...

    but I didn't manage to display the current microsecond under windows, therefore I was wondering if anybody here had an example or an easy way to do that.
    • The Manual said the program required Win95 or better, so I installed Linux.
    • Newton was a pessimist.
    • no Risk! no FuN!

  8. #8
    Join Date
    Feb 2006
    Location
    US
    Posts
    173
    Thanks
    16
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Current Time with microsecond precision on windows

    Are you trying to handle something with a hard real-time requirement? I've heard of extensions (patches to kernel) for Windows to do this.

    Most timers (at least standard APIs) that I've used only have a resolution of 1 millisecond ... even though they may indicate a higher resolution value.

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Current Time with microsecond precision on windows

    It would be hard to get higher resolutions with standard system as the internal system clock would have to tick with frequency higher than 1kHz, meaning there would need to be more than 1000 clock interrupts per second.

  10. #10
    Join Date
    Mar 2006
    Location
    somewhere between France & Germany
    Posts
    34
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Current Time with microsecond precision on windows

    Linux can.
    gettimeofday() is accurate to the microsecond
    • The Manual said the program required Win95 or better, so I installed Linux.
    • Newton was a pessimist.
    • no Risk! no FuN!

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Current Time with microsecond precision on windows

    Are you sure it doesn't only display in microseconds? I believe microseconds can be obtained when using hardware alarms from the real time clock, but I doubt system clock can be that accurate on its own. AFAIR modern Linux distros on i386 architecture have the clock interrupts set at 1kHz, so it would mean they can measure time with accuracy of 0.001s = 1ms. This is only my logic explanation, if someone knows better, please say so.

  12. #12
    Join Date
    Mar 2006
    Location
    somewhere between France & Germany
    Posts
    34
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Current Time with microsecond precision on windows

    you mean it just gives a millisecond accurate time and the microseconds are a kind of rand() % 999 ?
    • The Manual said the program required Win95 or better, so I installed Linux.
    • Newton was a pessimist.
    • no Risk! no FuN!

  13. #13
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Current Time with microsecond precision on windows

    Quote Originally Posted by Dwarf007
    you mean it just gives a millisecond accurate time and the microseconds are a kind of rand() % 999 ?
    Or set to 0. But generaly yes, it might be so.

  14. #14
    Join Date
    Mar 2006
    Location
    somewhere between France & Germany
    Posts
    34
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Current Time with microsecond precision on windows

    *grumpfl*

    Ok thanks.. I think I will do something like that then.. (rand() % 999)
    • The Manual said the program required Win95 or better, so I installed Linux.
    • Newton was a pessimist.
    • no Risk! no FuN!

  15. #15
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Current Time with microsecond precision on windows

    Why do you need microseconds anyway?

  16. #16
    Join Date
    Mar 2006
    Location
    somewhere between France & Germany
    Posts
    34
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Thumbs up [SOLVED] Current Time with microsecond precision on windows

    wysota: I want to do a kind of portable and accurate gettimeofday();

    Here is the solution, in case someone wants to do the same one day.
    No garantie on it but it seems to work.

    Windows part for a portable gettimeofday():

    Qt Code:
    1. #ifdef _WIN32_
    2.  
    3. #include <windows.h>
    4.  
    5. int gettimeofday( struct timeval *tv, struct timezone *tz )
    6. {
    7. time_t rawtime;
    8.  
    9. time(&rawtime);
    10. tv->tv_sec = (long)rawtime;
    11.  
    12. // here starts the microsecond resolution:
    13.  
    14. LARGE_INTEGER tickPerSecond;
    15. LARGE_INTEGER tick; // a point in time
    16.  
    17. // get the high resolution counter's accuracy
    18. QueryPerformanceFrequency(&tickPerSecond);
    19.  
    20. // what time is it ?
    21. QueryPerformanceCounter(&tick);
    22.  
    23. // and here we get the current microsecond! \o/
    24. tv->tv_usec = (tick.QuadPart % tickPerSecond.QuadPart);
    25.  
    26. return 0;
    27. }
    28. #endif // _WIN32_
    To copy to clipboard, switch view to plain text mode 
    Last edited by Dwarf007; 4th April 2006 at 12:53.
    • The Manual said the program required Win95 or better, so I installed Linux.
    • Newton was a pessimist.
    • no Risk! no FuN!

  17. #17
    Join Date
    Jan 2006
    Location
    Munich, Germany.
    Posts
    111
    Thanks
    29
    Thanked 3 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Current Time with microsecond precision on windows

    .... and here's a class using those funcs (if it's any help)

    K
    Attached Files Attached Files

Similar Threads

  1. Distributing QT application for Mac OS
    By mb0 in forum Qt Programming
    Replies: 1
    Last Post: 31st May 2007, 18:59
  2. Replies: 15
    Last Post: 21st April 2007, 17:46

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.