Get the current local time with ctime [C++]
#include <iostream>
#include <ctime>
int main()
{
time_t currentTime;
struct tm *localTime;
time( ¤tTime ); // Get the current time
localTime = localtime( ¤tTime ); // Convert the current time to the local time
int Day = localTime->tm_mday;
int Month = localTime->tm_mon + 1;
int Year = localTime->tm_year + 1900;
int Hour = localTime->tm_hour;
int Min = localTime->tm_min;
int Sec = localTime->tm_sec;
cout << "This program was exectued at: " << Hour << ":" << Min << ":" << Sec<<endl ;
cout << "And the current date is: " << Day << "/" << Month << "/" << Year <<endl;
return 0;
}
#include <ctime>
int main()
{
time_t currentTime;
struct tm *localTime;
time( ¤tTime ); // Get the current time
localTime = localtime( ¤tTime ); // Convert the current time to the local time
int Day = localTime->tm_mday;
int Month = localTime->tm_mon + 1;
int Year = localTime->tm_year + 1900;
int Hour = localTime->tm_hour;
int Min = localTime->tm_min;
int Sec = localTime->tm_sec;
cout << "This program was exectued at: " << Hour << ":" << Min << ":" << Sec<<endl ;
cout << "And the current date is: " << Day << "/" << Month << "/" << Year <<endl;
return 0;
}
Post a Comment