Thursday, 20 August 2015

Time and Date in 'C++'












Sometimes,we need to add time and date in our 'c++' programs.
For that,here are two functions which can be used to add these utilities.
|----------------------------------------------------|
|   for adding time  ->   _strtime(variable);   |
|   for adding date  ->   _strdate(variable);    |
|----------------------------------------------------|

The headerfile for these functions is '<time.h>'.

for example :-

#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include<time.h>
void main()
{
    clrscr();
    char date[10];
    char time[10];
    _strdate(date);           \\function for fetching 'system date'
    cout<<"The current date is  \n"<<date<<"\n" ;
    _strtime(time);          \\function for fetching 'system time'
    cout<<"The current time is \n"<<time<<"\n";
    system("pause");
}


 Use _strtime_s and _strdate_s instead for security sensitive programs.

No comments:

Post a Comment