Logo

Programming-Idioms

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

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

new Date (ts * 1000)

JavaScript is big on type conversion.
Date is back from the olden days where we ripped our stuff from Java instead of Python :3
#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