ctime() Function in C/C++ Last Updated : 26 Jun, 2023 Comments Improve Suggest changes Like Article Like Report 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 yyyyTime 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: C++ #include <iostream> #include <ctime> int main() { // create a time_t object representing 1 hour from now time_t one_hour_from_now = time(0) + 3600; // convert one_hour_from_now to string form char* dt = ctime(&one_hour_from_now); // print the date and time std::cout << "One hour from now, the date and time will be: " << dt << std::endl; return 0; } C // C program to demonstrate // ctime() function. #include <stdio.h> #include <time.h> int main () { time_t curtime; time(&curtime); printf("Current time = %s", ctime(&curtime)); return(0); } Output: One hour from now, the date and time will be: Thu Apr 13 09:01:46 2023 Comment More infoAdvertise with us Next Article ctime() Function in C/C++ B bansal_rtk_ Follow Improve Article Tags : C Language Similar Reads c16rtomb() function in C/C++ The c16rtomb() is a built-in function in C/C++ which converts 16 bit character representation to a narrow multibyte character representation. It is defined within the uchar.h header file of C++. Syntax: size_t c16rtomb(char* s, char16_t c16, mbstate_t* p) Parameters: The function accepts three manda 2 min read clock() function in C The clock() function in C returns the approximate processor time that is consumed by the program which is the number of clock ticks used by the program since the program started. The clock() time depends upon how the operating system allocates resources to the process that's why clock() time may be 2 min read Functions in C++ A function is a building block of C++ programs that contains a set of statements which are executed when the functions is called. It can take some input data, performs the given task, and return some result. A function can be called from anywhere in the program and any number of times increasing the 9 min read strtod() function in C/C++ The strtod() is a builtin function in C and C++ STL which interprets the contents of the string as a floating point number and return its value as a double. It sets a pointer to point to the first character after the last valid character of the string, only if there is any, otherwise it sets the poi 4 min read User-Defined Function in C A user-defined function is a type of function in C language that is defined by the user himself to perform some specific task. It provides code reusability and modularity to our program. User-defined functions are different from built-in functions as their working is specified by the user and no hea 6 min read Like