Thread: Help with time in C, how do you even do this?

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    29

    Help with time in C, how do you even do this?

    in my program i want to get the current time when the program starts, then be able to get the current time anytime later, I don't care how the format of the time is, but the thing is i want to be able to compare the times to get a difference in terms of minutes where it can be a integer or float.

    I have a auction type of program, where items get expires after a certain amount of time, so i want to know how much time passed at anytime i call a function or something, so i can determine if a item needs to be expired.

    How would i do this?

    Also when i create an item, i need to give it a parameter (for the amount of time it is available) , how should i give it, for most items it will be 5 min., so i figure putting a 5 is ok?

  2. #2
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,834
    Code:
    #include <time.h>
    ...
    
    time_t beginning, current;
    
    /* at start of program */
    time(&beginning); /* save the current time */
    
    /* sometime during the execution of program */
    time(&current); /* what is time now? */
    
    /* current - beginning is the number of seconds elapsed */

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help fast
    By blackice in forum C Programming
    Replies: 2
    Last Post: 01-31-2011, 01:19 PM
  2. Partition and scheduling HW/SW help!
    By thangdc01_02 in forum C++ Programming
    Replies: 3
    Last Post: 11-18-2010, 02:07 PM
  3. How to get current time
    By tsubasa in forum C Programming
    Replies: 3
    Last Post: 05-01-2009, 02:03 AM
  4. Help with assignment!
    By RVDFan85 in forum C++ Programming
    Replies: 12
    Last Post: 12-03-2006, 12:46 AM
  5. time class
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 12-11-2001, 10:12 PM