Thread: help in time.h

  1. #1
    Registered User
    Join Date
    Feb 2016
    Posts
    15

    help in time.h

    Hey Guys ,
    The Following Code is Just for Displaying time..
    Can Someone Tell me what
    time_t t does?
    and time(&t) means?
    And why there is ctime(&t) in printf?
    Code:
    main(){
    time_t t;
    time(&t);
    
    
    
    
       printf("Today's date and time : %s",ctime(&t));
    }

  2. #2
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    Where did you get this code from? If that source does not contain an explanation, I'd suggest you do a search for "time.h" tutorials. Also, looking up the functions you're uncertain about is a good way to get more information on what they do.

  3. #3
    Registered User
    Join Date
    Jan 2016
    Location
    India
    Posts
    4
    time_t
    The time_t datatype is a data type in the ISO C library defined for storing system time values. Such values are returned from the standard time() library function. This type is a typedef defined in the standard <time.h> header.
    Reference:
    https://en.wikibooks.org/wiki/C_Prog.../time.h/time_t
    Code to get system date and time:
    Code:
    
    
    Code:
    int main()
    {
        time_t T= time(NULL);
        struct  tm tm = *localtime(&T);
    
        printf("System Date is: %02d/%02d/%04d\n",tm.tm_mday, tm.tm_mon+1, tm.tm_year+1900);
        printf("System Time is: %02d:%02d:%02d\n",tm.tm_hour, tm.tm_min, tm.tm_sec);
    
        return 0;
    }

    Reference:
    http://www.includehelp.com/c-programs/system-date-time-linux.aspx








Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how convert uint32_t time to human read form of time?
    By barracuda in forum C Programming
    Replies: 19
    Last Post: 03-21-2015, 12:29 AM
  2. Replies: 5
    Last Post: 04-17-2013, 11:32 PM
  3. Replies: 2
    Last Post: 04-17-2013, 12:25 AM
  4. Replies: 23
    Last Post: 05-22-2011, 11:20 PM
  5. Replies: 7
    Last Post: 11-21-2009, 01:02 AM