Skip to content

Latest commit

 

History

History
38 lines (29 loc) · 910 Bytes

time-elapsed-since-epoch.md

File metadata and controls

38 lines (29 loc) · 910 Bytes
title timestamp author published description tags todo
Get the time elapsed since the epoch using only std
2024-02-10 02:40:01 -0800
szabgab
true
Get the nanoseconds elapsed since January 1, 1970, the beginning of the (UNIX) world.
time
SystemTime
UNIX_EPOCH
epoch
same using chrono
link to chrono

In this example using only std, the standard library we fetch the time elapsed since the epoch (which is 1970 January 1 on Unix/Linux systems).

{% include file="examples/epoch/src/main.rs" %}

Running on Linux this is the output:

$ cargo run -q

start:           SystemTime { tv_sec: 1707553108, tv_nsec: 951575643 }
since_the_epoch: 1707553108.951575643s
as_nanos:        1707553108951575643
as_micros:       1707553108951575
as_millis:       1707553108951
as_secs:         1707553108
as_secs_f32:     1707553200
as_secs_f64:     1707553108.9515758