Logo

Programming-Idioms

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

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

extern crate chrono;
use chrono::prelude::*;
let d = NaiveDateTime::from_timestamp(ts, 0);
#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