C time()

The time() function returns the current calendar time of the system. If the system has no time, -1 is returned.

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.

time() Syntax

Following is the syntax of the time() function :

time_t time(time_t *time);

time() Example

Following program displays the local time defined by the system :

void main()
	struct tm *ptr;
	time_t lt;
	lt = time(NULL);
	ptr = localtime(&lt);

C Online Test

« Previous Function C Tutorial »

Like/Share Us on Facebook 😋