VOOZH about

URL: https://www.geeksforgeeks.org/c/ctime-function-in-c-c/

⇱ ctime() Function in C/C++ - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

ctime() Function in C/C++

Last Updated : 26 Jun, 2023

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.

Syntax:

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.

Example:

Www Mmm dd hh:mm:ss yyyy

Time Complexity: O(1)
Auxiliary Space: O(1)

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.

Example:

Output:

One hour from now, the date and time will be: Thu Apr 13 09:01:46 2023
Comment
Article Tags:
Article Tags: