Get the system time
Syntax
C time function has the following syntax.
time_t time(time_t *time);
Header
C time function
is from header file time.h
.
Description
C time function returns the current calendar time of the system or -1 if the system has no time.
The time()
function can be called either with a
null pointer or with a pointer to a variable of type time_t
.
If the latter is used, the variable will also
be assigned the calendar time.
Example
Use C time function to get the systme time.
#include <time.h>
#include <stdio.h>
/* w w w . j a v a2s . c om*/
int main(void)
{
struct tm *ptr;
time_t lt;
lt = time(NULL);
ptr = localtime(<);
printf(asctime(ptr));
return 0;
}
The code above generates the following result.