On this page
  1. asctime
  2. Include
  3. Signature & Overview
  4. Notes & Pitfalls
  5. Example

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

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