0
How to print current date and time in c++? If anyone knows than please explain in comments below.
6 Antworten
+ 3
You can use functions from the <ctime> header:
Example: https://code.sololearn.com/cjmyqE7lUZG6/?ref=app
Link: http://www.cplusplus.com/reference/ctime/
Or directly the macros __DATE__ and __TIME__ with cout.
+ 2
C and C++ provide a well-defined preprocessor constants group which is mostly used for logging the compilation time, date, and several other facilities like returning C++'s current version by which the code is being compiled. __TIME__ and __DATE__ return string literals as the form of "hh:mm:ss" and "month day year", respectively.
~possible usage~
#define TIME __TIME__
#define DATE __DATE__
int main() {
cout << "Compilation time " << TIME << endl;
cout << "Compilation date "DATE << endl;
}
possible output:
Compilation time 20:29:34
Compilation date Jul 10 2018
+ 1
thanks to all for your support 🤘😊
+ 1
thanks naitomia for giving me brief explanation and exact answer... you've cleared my doubts as well... 😊🤘👍
0
thank you Hatsy for your valuable advise 😊👍