0

How to print current date and time in c++? If anyone knows than please explain in comments below.

10th Jul 2018, 3:17 PM
Shubham Chaurasia
Shubham Chaurasia - avatar
6 Answers
+ 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.
10th Jul 2018, 3:27 PM
Shadow
Shadow - avatar
10th Jul 2018, 3:26 PM
Hatsy Rei
Hatsy Rei - avatar
+ 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
10th Jul 2018, 3:56 PM
To Seek Glory in Battle is Glorious
To Seek Glory in Battle is Glorious - avatar
+ 1
thanks to all for your support đŸ€˜đŸ˜Š
10th Jul 2018, 4:00 PM
Shubham Chaurasia
Shubham Chaurasia - avatar
+ 1
thanks naitomia for giving me brief explanation and exact answer... you've cleared my doubts as well... đŸ˜ŠđŸ€˜đŸ‘
10th Jul 2018, 4:16 PM
Shubham Chaurasia
Shubham Chaurasia - avatar
0
thank you Hatsy for your valuable advise 😊👍
10th Jul 2018, 3:59 PM
Shubham Chaurasia
Shubham Chaurasia - avatar