|
|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Defined in header <ctime> | ||
char* ctime(conststd::time_t* time); | ||
Converts given time since epoch to a calendar local time and then to a textual representation, as if by callingstd::asctime(std::localtime(time)). The resulting string has the following format:
Www Mmm dd hh:mm:ss yyyy\n
Www - the day of the week (one ofMon,Tue,Wed,Thu,Fri,Sat,Sun).Mmm - the month (one ofJan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec).dd - the day of the month.hh - hours.mm - minutes.ss - seconds.yyyy - years.The function does not support localization.
Contents |
| time | - | pointer to astd::time_t object specifying the time to print |
Pointer to a static null-terminated character string holding the textual representation of date and time. The string may be shared betweenstd::asctime andstd::ctime, and may be overwritten on each invocation of any of those functions.
This function returns a pointer to static data and is not thread-safe. In addition, it modifies the staticstd::tm object which may be shared withstd::gmtime andstd::localtime. POSIX marks this function obsolete and recommendsstd::strftime instead.
The behavior may be undefined for the values ofstd::time_t that result in the string longer than 25 characters (e.g. year 10000).
#include <cassert>#include <cstring>#include <ctime>#include <iostream> int main(){std::time_t result=std::time(nullptr);std::cout<< std::ctime(&result); char buffer[32];std::strncpy(buffer, std::ctime(&result),26);assert('\n'== buffer[std::strlen(buffer)-1]);std::cout<< buffer;}
Possible output:
Mon Oct 11 17:10:55 2021Mon Oct 11 17:10:55 2021
| converts astd::tm object to a textual representation (function)[edit] | |
| converts astd::tm object to custom textual representation (function)[edit] | |
(C++11) | formats and outputs a date/time value according to the specified format (function template)[edit] |
C documentation forctime | |