
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
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);
- Related Articles
- How to get current date and time in Python?
- How to get current date and time in JavaScript?
- How to get current date and time using JavaScript?
- How to get the current date and time in Java?
- How to get current date and time from internet in iOS?
- How to get current date and time from internet in android?
- How to get the current local date and time in Kotlin?
- Get current time and date on Android
- How to get current date/time in seconds in JavaScript?
- Java Program to Get Current Date/Time
- How can I get the current time and date in Kotlin?
- How do I get the current date and time in JavaScript?
- Get current date/time in seconds - JavaScript?
- How to get current date/time in milli seconds in Java?
- How to get the current date and time from the internet in Android using Kotlin?

Advertisements