time -- Determine Current Time

Format

#include <time.h>
time_t time(time_t *timeptr);

Language Level: ANSI, POSIX, XPG4
time determines the current calendar time in seconds.

The current calendar time in seconds, on both OS/2 and Windows, is not necessarily the local time localtime.

Note:
Calendar time is the number of seconds that have elapsed since EPOCH, which is 00:00:00, January 1, 1970 Universal Coordinate Time (UTC).

On both OS/2 and Windows, the time and date functions begin at 00:00:00 Universal Time, January 1, 1970, and do not have an upper limit.

Return Value
time returns the current calendar time. The return value is also stored in the location given by timeptr. If timeptr is NULL, the return value is not stored. If the calendar time is not available, the value (time_t)(-1) is returned.

Example
This example gets the time and assigns it to ltime. ctime then converts the number of seconds to the current date and time. This example then prints a message giving the current time.

#include <time.h>
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
   time_t ltime;
   if(time(&ltime) == -1)
{
   printf("Calendar time not available.\n");
   exit(1);
}
     printf("The time is %s\n", ctime(&ltime));
     return 0;
   /**********************************************
      The output should be similar to:
      The time is Thu Jan 12 11:38:37 1995
   **********************************************/
}


asctime -- Convert Time to Character String
ctime -- Convert Time to Character String
gmtime -- Convert Time
localtime -- Convert Time
mktime -- Convert Local Time
_strtime -- Copy Time
<time.h>