Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Reading System clock through C

  • 15-12-2003 3:08pm
    #1
    Closed Accounts Posts: 45


    This may be an easy question to answer,but I've spent the last week asking various people and trying to find an answer on the net with no luck.What I want to do is be able to read the time and date from the system clock using a C program,but I have no idea if there's a function to do this,and if so how do I use it?Any help would be appreciated.


Comments

  • Registered Users, Registered Users 2 Posts: 21,264 ✭✭✭✭Hobbes




  • Closed Accounts Posts: 423 ✭✭Dizz


    Actually a Q...
    What's the granularity of that function?
    Is it 20ms? ie based on the system clock. Is there a way to get finer granularity with out changing hardware arch.?

    Dizz


  • Registered Users, Registered Users 2 Posts: 491 ✭✭Silent Bob


    Originally posted by Dizz
    Actually a Q...
    What's the granularity of that function?
    Is it 20ms? ie based on the system clock. Is there a way to get finer granularity with out changing hardware arch.?

    Dizz
    time.h gives you accuracy to the second.

    If you don't mind losing cross-platformness you can use gettimeofday()

    It's a *nix system call that gives you values down to the microsecond. I wouldn't know the exact win32 equivalent...


  • Registered Users, Registered Users 2 Posts: 2,152 ✭✭✭dazberry


    Originally posted by Silent Bob

    It's a *nix system call that gives you values down to the microsecond. I wouldn't know the exact win32 equivalent...

    DWORD GetTickCount(VOID);


  • Registered Users, Registered Users 2 Posts: 491 ✭✭Silent Bob


    MSDN says that GetTickCount() returns the number of milliseconds since the system was started, not the time. Although a quick search says that GetSystemTime gives you date/time accurate to milliseconds.


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 21,264 ✭✭✭✭Hobbes


    failing that you could just get the tick count from the start of your program and link to the time, then use the next tick count to get the difference in time better.

    But the functions should already be there to do this.


  • Registered Users, Registered Users 2 Posts: 2,152 ✭✭✭dazberry


    Originally posted by Silent Bob
    MSDN says that GetTickCount() returns the number of milliseconds since the system was started, not the time. Although a quick search says that GetSystemTime gives you date/time accurate to milliseconds.

    Yeap, sorry should have read the whole thread.

    D.


Advertisement