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

strftime

Prev: timespec_get | Up: time.h | Next: gmtime
Rel: time.h, math, time & assert Guide
Ref: cppreference — strftime
Tags: #public #prog #c #stdlib #time #tier/core


Include

#include <time.h>

Signature & Overview

size_t strftime(char *restrict buf, size_t max, const char *restrict fmt, const struct tm *restrict tm);

Formats a broken-down struct tm into buf safely with bounds checking (ISO-8601: "%Y-%m-%dT%H:%M:%SZ").

Notes & Pitfalls

Example

#include <assert.h>
#include <string.h>
#include <time.h>

int main(void) {
    time_t epoch = 0;
    char out[32];
    size_t n = strftime(out, sizeof(out), "%Y-%m-%dT%H:%M:%SZ", gmtime(&epoch));
    assert(n > 0 && strcmp(out, "1970-01-01T00:00:00Z") == 0);
}

Linked from

Related notes