std-method

Duration::new: seconds and nanoseconds

Construct an interval using separate units. Excess nanoseconds carry into the seconds field; an overflow of the seconds field panics. The normalized fractional part is always below one billion. Expected stdout (not executed): 3 500000000 Common mistake: Assuming the second argument is milliseconds.

Formal Syntax & Structure

rust syntaxrust
Duration::new(secs: u64, nanos: u32) -> Duration

Working Example

Example Snippetrust
fn main() {    use std::time::Duration;    let d = Duration::new(2, 1_500_000_000);    println!("{} {}", d.as_secs(), d.subsec_nanos());}
Rust Reference