Convertools Dev
All tools

Unix Timestamp in C

Look up the current epoch time and convert between Unix seconds and UTC dates in C.

Get the current timestamp

#define _DEFAULT_SOURCE
#include <stdio.h>
#include <time.h>

int main(void) {
    printf("%lld\n", (long long)time(NULL));
}

Timestamp to date

#define _DEFAULT_SOURCE
#include <stdio.h>
#include <time.h>

int main(void) {
    time_t seconds = 1700000000;
    char text[32];
    strftime(text, sizeof text, "%Y-%m-%dT%H:%M:%SZ", gmtime(&seconds));
    puts(text);
}

Date to timestamp

#define _DEFAULT_SOURCE
#include <stdio.h>
#include <time.h>

int main(void) {
    struct tm utc = { .tm_year = 2023 - 1900, .tm_mon = 11 - 1,
                      .tm_mday = 14, .tm_hour = 22, .tm_min = 13, .tm_sec = 20 };
    printf("%lld\n", (long long)timegm(&utc));
}

Open 1700000000 in the converter

Current Unix time

Seconds—
Milliseconds—
UTC
—
My time zone
—

Official reference ↗

Free to use. Your input stays in this browser.

How to use it

  1. Copy the current-time example into your C environment to read Unix seconds.
  2. Run the second example to display 1700000000 as a UTC date.
  3. Run the last example to convert that date back into seconds.

On POSIX systems, time_t represents seconds. gmtime() formats in UTC, and timegm() is its inverse on systems such as macOS and glibc. A 32-bit time_t has a 2038 limit.