codescracker


c

C time()



« Previous Function C Tutorial »


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 :

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

time() Example

Following program displays the local time defined by the system :

#include<time.h>
#include<stdio.h>
#include<conio.h>
void main()
{
	clrscr();
	
	struct tm *ptr;
	time_t lt;
	lt = time(NULL);
	ptr = localtime(&lt);
	printf(asctime(ptr));
	
	getch();
}

« Previous Function C Tutorial »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test