In this cpp date example we will learn how to display current date and time. For this example we import two packages #include<cmath> Examples This will return below out for the current date
As a beginner programmer you should also know about how to Conver String to Char Array using C++
#include <ctime>
#include<iostream>
#include<cmath>
#include <ctime>
using namespace std;
int main()
{
time_t t = time(NULL);
tm* timePtr = localtime(&t);
cout << "seconds= " << (timePtr->tm_sec) << endl;
cout << "minutes = " << (timePtr->tm_min) << endl;
cout << "hours = " << (timePtr->tm_hour) << endl;
cout << "day of month = " << (timePtr->tm_mday) << endl;
cout << "month of year = " << (timePtr->tm_mon)+1 << endl;
cout << "year = " << (timePtr->tm_year)+1900 << endl;
cout << "weekday = " << (timePtr->tm_wday )<< endl;
cout << "day of year = " << (timePtr->tm_yday )<< endl;
cout << "daylight savings = " <<(timePtr->tm_isdst )<< endl;
cout << endl;
cout << endl;
cout << "Date " <<(timePtr->tm_mday)<<"/"<< (timePtr->tm_mon)+1 <<"/"<< (timePtr->tm_year)+1900<< endl;
cout << "Time " << (timePtr->tm_hour)<<":"<< (timePtr->tm_min)<<":"<< (timePtr->tm_sec) << endl;
return 0;
}
Time manipulation
computes the difference between times
(function)
returns the current time of the system as time since epoch
(function)
returns raw processor clock time since the program is started
(function)
returns the calendar time based on a given time base
(function)
Format conversions
converts a
tm
object to a textual representation
(function)
converts a
time_t
object to a textual representation
(function)
converts a
tm
object to custom textual representation
(function)
converts a
tm
object to custom wide string textual representation
(function)
converts time since epoch to calendar time expressed as Universal Coordinated Time
(function)
converts time since epoch to calendar time expressed as local time
(function)
converts calendar time to time since epoch
Article Contributed By :
|
|
|
|
1675 Views |