- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to get current time and date in C++?
Here is an example to get current date and time in C++ language,
Example
#include <iostream> using namespace std; int main() { time_t now = time(0); char *date = ctime(& now); cout << "The local date and time : " << date << endl; }
Output
Here is the output
The local date and time : Wed Oct 3 08:35:24 2018
In the above program, the code to get current date and time is present in main(). Here, time_t is the return type of variable now. In-built function time() is used to get the local current time and date.
time_t now = time(0); char *date = ctime(& now);
Advertisements