+ 11
How to get current time in C++?
I think it is done by importing <ctime.h> but what is the exact procedure to display time as output?
4 Answers
+ 9
An example of the use of ctime.
I have used ctime in this count down
https://code.sololearn.com/cdBAJw9Lhy65/?ref=app
+ 8
Gives The GMT timing
cout<<__TIME__;
+ 5
time(NULL) will return amount of seconds from 01.01.1970 00:00. Then you can get current date and time using mathematics, for example, (this amount)%60 is what second is now.
+ 3
don't use <ctime.h> use <ctime> in C++.
and you're right, you'll need to use ctime.
time_t raw;
time(&raw);
struct tm* current = local time(&raw);
string currentTime = asctime(current);
obviously you can use something like boost which would be efficient as this is.