Time.h and GetTickCount()

This is a discussion on Time.h and GetTickCount() within the C++ Programming forums, part of the General Programming Boards category; I am writing a simple little julian time conversion program this is the main function that I want to loop ...

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    10

    Time.h and GetTickCount()

    I am writing a simple little julian time conversion program this is the main function that I want to loop

    void main()
    {
    Julian Date;
    Date.GetTime();
    Date.CurrentJulianTime();
    }


    Bassicaly it displays the current time, and the converted date to julian.

    How can I use get tick count to make this refresh every second like a normal clock would and exit when I hit q?.. As it its now it only runs through once then stops

  2. #2
    I am the worst best coder Quantrizi's Avatar
    Join Date
    Mar 2002
    Posts
    644
    1. Get Tick Amount won't work, it's a random number generator. It's mainly used to see who will go first in a RPG, and stuff like that.

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    What function are you using to get the time?
    Here's a simple example using the time() function.
    The kbhit() function is true if a key was pressed. It's in conio.h on my compiler.
    Code:
       time_t tim, time_last;
       char *print_time;
    
       time_last = time(NULL);
       print_time = ctime(&time_last);
       cout << print_time << endl;
       do {
          tim = time(NULL);
          if (tim != time_last)
          {
             print_time = ctime(&tim);
             cout << print_time << endl;
             time_last = tim;
          }
    
       } while (!kbhit());
    I guess you could use GetTickCount(), though it's in millisecs.

  4. #4
    Unregistered
    Guest
    The time just is similar to the way you hace it there, I just put the time in a structure and read it all out...

    Thenn convert it to julian time. I figured by looping the main function there I could make the clock and the conversion run repeatidy creating a LIVE time converter.

  5. #5
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Originally posted by Quantrizi
    1. Get Tick Amount won't work, it's a random number generator. It's mainly used to see who will go first in a RPG, and stuff like that.
    No, GetTickCount() returns the number of milliseconds passed since windows started.

    From Borlands WinAPI help files

    The GetTickCount function retrieves the number of milliseconds that have elapsed since Windows was started.

    DWORD GetTickCount(VOID)


    Parameters

    This function has no parameters.

    Return Value

    If the function succeeds, the return value is the number of milliseconds that have elapsed since Windows was started.

    Remarks

    The GetTickCount function is identical to the GetCurrentTime function. Applications should use the GetTickCount function because its name matches more closely what the function does.
    The GetTickCount and GetMessageTime functions return different times. GetMessageTime returns the Windows time when the given message was created, not the current Windows time.
    The internal timer wraps around to zero if Windows is run continuously for approximately 49.7 days.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with Sleep and GetTickCount().
    By IamBMF in forum C Programming
    Replies: 13
    Last Post: 02-03-2008, 09:25 AM
  2. GetTickCount()
    By ElastoManiac in forum Windows Programming
    Replies: 3
    Last Post: 12-17-2005, 03:49 PM
  3. Something like GetTickCount()
    By rmullen3 in forum C++ Programming
    Replies: 3
    Last Post: 02-08-2003, 09:32 PM
  4. timeGetTime(), getSystemTime(), GetTickCount()
    By Shadow12345 in forum Windows Programming
    Replies: 1
    Last Post: 11-02-2002, 10:35 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21