Home C-tutorials C Current Time



C Current Time
Posted on: February 5, 2009 at 12:00 AM
The header file provides all date and time functions. In the given example, the time() function determines the current time in seconds and assigns it to time_t type variable t.

C Current Time

     

In this section, you will learn how to get the current time in C. 

The header file <time.h> provides all date and time functions. In the given example, the time() function determines the current time in seconds and assigns it to time_t type variable t. The ctime() function converts the number of seconds to the current date and time. The printf() function then prints the current date and time.

Here is the code:

CURRENTT.C

 


#include <time.h>
#include <stdio.h>
#include <conio.h>
void main() {
  time_t t;
  time(&t);
  printf("The current Date and Time is: %s\n", ctime(&t));
  getch();
}

Output will be displayed as:

CURRENTT.EXE

Download Source Code:

 

Related Tags for C Current Time:
cfileidedatetimefunctionsfunctionfunioheadervariabletypevirmiriaidexampleunctoexamssieilsignitdesvarpeimcurrentinrmasmheadntminminadesfuncallmeprotime.hxaxampstermatimellivmpleaandarsecondsvassrirenthcondababletermetermpleplprmindono


More Tutorials from this section

Ask Questions?    Discuss: C Current Time   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.