Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Go

Idiom #98 Epoch seconds to date object

Convert a timestamp ts (number of seconds in epoch-time) to a date with time d. E.g. 0 -> 1970-01-01 00:00:00

import "time"
d := time.Unix(ts, 0)

ts has type int64.
The second argument is nanoseconds.
#include <chrono>
#include <ctime>
std::time_t d = std::chrono::system_clock::to_time_t(ts);

ts is a time_point (epoch)

New implementation...
< >
elbrujohalcon