Thread: Time header

  1. #1
    Registered User
    Join Date
    Jul 2002

    Time header

    I need someone to direct me to a simple but thorough explanation of the time funtions cos I can;t make head nor tail off them.

    I want to print the time now and be able to calculate time difference.


  2. #2
    Registered User
    Join Date
    Jul 2002
    time_t time() will give you time passed since epoch which is 00:00:00 January 1 1970. To find out difference between two times, you need to create the time_t entries for both times and subtract the two. This will give you number of seconds difference between the two times.

    use mktime to get seconds from epoch for a given time. The parameters to mktime are a structure pointer to tm

    tm takes the following values -->
    1) tm_sec --> seconds in your time
    2) tm_min
    3) tm_hour
    4) tm_mday --> day of month
    5) tm_mon --> month
    6) tm_year --> no of years since 1900

    The rest of the info you can ignore.

    subtract the two time_t values will get you the difference.

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    My best code is written with the delete key.

  4. #4
    Registered User
    Join Date
    Dec 2001
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    char *get_system_time_();
    int main() {
      printf("%s", get_system_time_());
      return 0;
    char *get_system_time_() {
      time_t now;
      return asctime(localtime(&now));

    Look in time.h to see all of the different functions that can be used, and the member data of struct tm.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Checking array for string
    By Ayreon in forum C Programming
    Replies: 87
    Last Post: 03-09-2009, 03:25 PM
  2. Read and set\change system time
    By Hexxx in forum C++ Programming
    Replies: 9
    Last Post: 01-02-2006, 07:11 AM
  3. Request for comments
    By Prelude in forum A Brief History of
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  4. time class
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 12-11-2001, 10:12 PM