Skip to content
Related Articles

Related Articles

Improve Article

ctime() Function in C/C++

  • Difficulty Level : Basic
  • Last Updated : 28 Sep, 2018

The ctime() function is define in the time.h header file. The ctime() function returns the string representing the localtime based on the argument timer.


char *ctime(const time_t *timer)

Parameters: This function accepts single parameter time_ptr. It is used to set time_t object that contains a time value.

Return Value: This function returns a string that contains the date and time which is in human readable form.

Www Mmm dd hh:mm:ss yyyy

Note: The description of results are given below:

  • Www: Day of week.
  • Mmm: Month name.
  • dd : Day of month.
  • hh : Hour digit.
  • mm : Minute digit.
  • ss : Second digit.
  • yyyy : Year digit.


// C program to demonstrate
//  ctime() function.
#include <stdio.h>
#include <time.h>
int main () {
    time_t curtime;
    printf("Current time = %s", ctime(&curtime));
Current time = Fri Sep 28 08:13:09 2018

Want to learn from the best curated videos and practice problems, check out the C Foundation Course for Basic to Advanced C.

My Personal Notes arrow_drop_up
Recommended Articles
Page :