asctime()
It is used to convert the contents in the structure filled by local time into a human-readable version which finally returns the day, date, and time in the given format:
Day Month Date hh:mm:ss Year
Example:
C++
// C++ Program to print current Day, Date and Time #include <ctime> #include <iostream> using namespace std; int main() { // Declaring argument for time() time_t tt; // Declaring variable to store return value of // localtime() struct tm * ti; // Applying time() time (&tt); // Using localtime() ti = localtime (&tt); cout << "Current Day, Date and Time is = " << asctime (ti); return 0; } |
Output
Current Day, Date and Time is = Thu Dec 29 06:35:15 2022
C++ Program to Print Current Day, Date and Time
In order to facilitate finding the current local day, date, and time, C++ has defined several functions in the header file, so functions that will help us in achieving our objective of finding the local day, date, and time are: time():
- It is used to find the current calendar time.
- Its return type is time_t, which is an arithmetic data type capable of storing time returned by this function.
- If its argument is not NULL, then it assigns its argument the same value as its return value.
Also, Calendar dates are displayed on the screen together with the day, date, and time that are current. All the date and time-related functions and variables in C++ are found in the ctime library.
Contact Us