Skip to content

Instantly share code, notes, and snippets.

@jweinst1
Created May 1, 2019 06:55
Show Gist options
  • Save jweinst1/0f0f2e9e31e487469e5367d42ad29253 to your computer and use it in GitHub Desktop.
Save jweinst1/0f0f2e9e31e487469e5367d42ad29253 to your computer and use it in GitHub Desktop.
Using rust to get the unix time in seconds as a number.
use std::time::{SystemTime};
fn get_sys_time_in_secs() -> u64 {
match SystemTime::now().duration_since(SystemTime::UNIX_EPOCH) {
Ok(n) => n.as_secs(),
Err(_) => panic!("SystemTime before UNIX EPOCH!"),
}
}
fn main() {
println!("Time is {}", get_sys_time_in_secs());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment