Time header

This is a discussion on Time header within the C Programming forums, part of the General Programming Boards category; I need someone to direct me to a simple but thorough explanation of the time funtions cos I can;t make ...

  1. #1
    Registered User
    Join Date
    Jul 2002
    Posts
    4

    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.

    Thanx

  2. #2
    Registered User
    Join Date
    Jul 2002
    Posts
    15
    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
    Posts
    9,796
    My best code is written with the delete key.

  4. #4
    Registered User
    Join Date
    Dec 2001
    Posts
    108
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    
    char *get_system_time_();
    
    int main() {
      printf("%s", get_system_time_());
      system("pause");
      return 0;
    }
    
    char *get_system_time_() {
      time_t now;
      time(&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, 06:11 AM
  3. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 09:33 AM
  4. time class
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 12-11-2001, 09:12 PM

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