On this page
asctime
Prev: gmtime | Up: time.h | Next: stdarg.h
Rel: strftime(), time.h
Ref: cppreference — asctime
Tags: #public #prog #c #stdlib #time #tier/legacy
Include
#include <time.h>
Signature & Overview
char *asctime(const struct tm *tm); /* also ctime */
Formats time into a fixed non-thread-safe static buffer with a trailing newline.
Legacy / Avoid: Prefer strftime() in all new code.
Notes & Pitfalls
- Deprecated & NOT thread-safe (static buffer, fixed English format): Always use
strftime()instead.
Example
#include <assert.h>
#include <time.h>
int main(void) {
time_t t = 0;
char buf[32];
assert(strftime(buf, sizeof(buf), "%Y-%m-%d", gmtime(&t)) == 10);
}
Linked from
Related notes
- tuts/c/stdlib/time/gmtime Linked here; links to this page; shared tags: #c, #prog, #stdlib, #tier, #time
- tuts/c/stdlib/time Linked here; links to this page; shared tags: #c, #prog, #stdlib, #time
- tuts/c/stdlib/time/strftime Linked here; shared tags: #c, #prog, #stdlib, #tier, #time
- tuts/c/stdlib/stdarg Linked here; shared tags: #c, #prog, #stdlib
- tuts/c/stdlib/time/time shared tags: #c, #prog, #stdlib, #tier, #time
- tuts/c/stdlib/time/timespec_get shared tags: #c, #prog, #stdlib, #tier, #time
- tuts/c/stdlib/assert/assert shared tags: #c, #prog, #stdlib, #tier
- tuts/c/stdlib/assert/static_assert shared tags: #c, #prog, #stdlib, #tier
- tuts/c/stdlib/ctype/isalpha shared tags: #c, #prog, #stdlib, #tier
- tuts/c/stdlib/ctype/isdigit shared tags: #c, #prog, #stdlib, #tier