Skip to content
Related Articles

Related Articles

Improve Article

asctime() function in C++

  • Difficulty Level : Medium
  • Last Updated : 01 Oct, 2018

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.


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 calender time in the form “Www Mmm dd hh:mm:ss yyyy”

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


// c++ program to demonstrate
// example of asctime() function.
#include <bits/stdc++.h>
using namespace std;
int main()
    time_t time_ptr;
    cout << "Current date and time = "
         << asctime(localtime(&time_ptr));
    return 0;
Current date and time = Mon Oct  1 10:21:26 2018
Want to learn from the best curated videos and practice problems, check out the C++ Foundation Course for Basic to Advanced C++ and C++ STL Course for foundation plus STL.  To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.
My Personal Notes arrow_drop_up
Recommended Articles
Page :