Results 1 to 7 of 7

Thread: [SOLVED] gettimeofday on Windows?

  1. #1
    Join Date
    May 2007
    Beans
    4,513
    Distro
    Ubuntu

    [SOLVED] gettimeofday on Windows?

    Hi all,

    I'm doing some experimentation with time on a simple C program. I got the Linux version to work okay with the help of gettimeofday, localtime. But on windows, I found that the timeval structure exists in winsock2.h, which doesn't have a gettimeofday..

    I searched around some, but I'm not familiar with programming resources for Windows. Can anyone help me out / point me in the right direction?

    I essentially want to be able to tell the current system time in hours, minutes, seconds, and miliseconds.

  2. #2
    Join Date
    Jan 2007
    Location
    New Jersey
    Beans
    355
    Distro
    Ubuntu

    Re: gettimeofday on Windows?

    Only thing i can suggest is create an fsock to udp://localhost:13 to connect to the time server on your machine.
    Fluxbox, PHP, CLI, Donuts and Chocolate Milk. All i need to say.

  3. #3
    Join Date
    May 2007
    Beans
    4,513
    Distro
    Ubuntu

    Re: gettimeofday on Windows?

    How efficient would that me? I'd need to check the time many times per second at times.

  4. #4
    Join Date
    Oct 2006
    Location
    Austin, Texas
    Beans
    2,715

    Re: gettimeofday on Windows?

    I'm fairly certain windows has it's own way of doing this, unfortunately I'm not a Window programmer so I can't help. You might try a Windows-specific forum for people who can probably help more.

  5. #5
    Join Date
    May 2007
    Location
    Paris, France
    Beans
    927
    Distro
    Kubuntu 7.04 Feisty Fawn

    Re: gettimeofday on Windows?

    The daytime service is NOT enabled on Windows by default. So I seriously doubt about the usefulness of that approach.

    A good resource for the Win32 API is http://msdn.microsoft.com

    And FWIW Google yields very relevant results when it comes to Windows equivalents of gettimeofday()...
    Not even tinfoil can save us now...

  6. #6
    Join Date
    May 2007
    Beans
    4,513
    Distro
    Ubuntu

    Re: gettimeofday on Windows?

    Here's how I did it in the end:

    #include <windows.h>

    SYSTEMTIME st;
    GetSystemTime(&st);

    Then you can use st.wHour, st.wMinute, st.wSecond, and st.wMilliseconds to retrieve the values (it has days, months in it too but I don't need them).

  7. #7
    Join Date
    Oct 2009
    Beans
    1

    Re: [SOLVED] gettimeofday on Windows?

    Even though this thread was marked as solved, the solution provide was not proper (i mean not complete), so for benefit of other I would like to point to complete solution http://www.cpp-programming.net/c-tid...n-for-windows/

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
  •