Skip to content
Related Articles
Get the best out of our app
GFG App
Open App
geeksforgeeks
Browser
Continue

Related Articles

asctime() function in C++

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

The asctime() function is defined in the ctime header file. The asctime() function converts the given calendar time of structure tm to a character representation i.e human readable form.

Syntax: 

char* asctime(const struct tm * time_ptr);

Parameter: This function accepts single parameter time_ptr i.e pointer to the tm object to be converted.

Return Value: This function returns the calendar time in the form “Www Mmm dd hh:mm:ss yyyy”

Below program illustrate the asctime() function in C++:

Example:- 

C++




// c++ program to demonstrate
// example of asctime() function.
 
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
    time_t time_ptr;
  
    time(&time_ptr);
    cout << "Current date and time = "
         << asctime(localtime(&time_ptr));
 
    return 0;
}


Output: 

Current date and time = Mon Oct  1 10:21:26 2018

 

My Personal Notes arrow_drop_up
Last Updated : 24 Sep, 2021
Like Article
Save Article
Similar Reads