Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created September 10, 2022 04:19
Show Gist options
  • Save rust-play/b08021e751bf8fb984013fd48803b297 to your computer and use it in GitHub Desktop.
Save rust-play/b08021e751bf8fb984013fd48803b297 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
use chrono::*;
const SECOND_IN_MICROSECONDS: i64 = 1_000_000;
const MICROSECOND_IN_NANOSECONDS: i64 = 1_000;
fn s(μs: i64) -> i64 { (μs / SECOND_IN_MICROSECONDS) as i64 }
fn ns(μs: i64) -> u32 { (μs.rem_euclid(SECOND_IN_MICROSECONDS) * MICROSECOND_IN_NANOSECONDS) as u32 }
fn main() {
let past_ms = -150_151_152_153_154;
let future_ms = 150_151_152_153_154;
let past = Utc.timestamp(s(past_ms), ns(past_ms));
println!("{past}");
let future = Utc.timestamp(s(future_ms), ns(future_ms));
println!("{future}");
}
@Roms1383
Copy link

Related to Dart gist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment