Logo

Programming-Idioms

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

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

Timestamp = {Seconds div 1000000, Seconds rem 1000000, 0},
calendar:now_to_universal_time(Timestamp).
#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