The asctime() function is defined in time.h header file. This function returns the pointer to the string that contains the information stored in the structure pointed to struct tm type. This function is used to return the local time defined by the system.
char *asctime(const struct tm* tm_ptr);
0Parameters: This function accepts single parameter time_ptr i.e pointer to the tm object to be converted.
Return Type: This function returns the calendar time in the form “Www Mmm dd hh:mm:ss yyyy”, where:
- Www: represents the day in three letter abbrivated (Mon, Tue, Wed.., )
- Mmm: represents the month in three letter abbrivated (Jan, Feb, Mar.., )
- dd: represents the date in two digits (01, 02, 10, 21, 31.., )
- hh: represents the hour (11, 12, 13, 22…, )
- mm: represents the minutes (10, 11, 12, 45…, )
- ss: represents the seconds (10, 20, 30…, )
- yyyy: represents the year in four digits (2000, 2001, 2019, 2020…, )
Below program demonstrate the asctime() function in C:
Wed Aug 14 04:21:25 2019
This function is used to convert the given calendar time into a textual representation. We can’t modify the output calendar time in asctime() function whereas we can modify the calendar time in asctime_s() function. The general syntax of asctime_s is “Www Mmm dd hh:mm:ss yyyy“.
errno_t asctime_s(char *buf, rsize_t bufsz, const struct tm *time_ptr)
Parameters: This function accepts three parameters:
- time_ptr: pointer to a tm object specifying the time to print
- buf: pointer to a user-supplied buffer at least 26 bytes in length
- bufsz: size of the user-supplied buffer
Return Value: This function returns pointer to a static null-terminated character string holding the textual representation of date and time. The original calendar time will be obtained from the asctime() function.
Note: In some C-compilers asctime_s() won’t be supported. We can use strftime() function instead of asctime_s() function.
Below program investigates the asctime_s() function in C:
Wed Aug 14 04:33:54 2019
- Commonly used String functions in C/C++ with Examples
- isalpha() and isdigit() functions in C with cstring examples.
- Functions in C/C++
- Nested functions in C
- Thread functions in C/C++
- Macros vs Functions
- C | Functions | Question 6
- C | Functions | Question 5
- C | Functions | Question 7
- Pure Functions
- C | Functions | Question 9
- C | Functions | Question 8
- C | Functions | Question 10
- Functions that cannot be overloaded in C++
- C | Functions | Question 11
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.