Library reference

Convert minutes to seconds

Each minute lasts 60 seconds. Convert the length of a wait into the unit a timer uses.

Duration::as_secs

Simple example

How many seconds are in two minutes?

Start2 min
Result120
main.rs
fn main() {
    let wait = std::time::Duration::from_secs(2 * 60);
    println!("{}", wait.as_secs());
}
Output
120
Advertisements

Everyday examples

The next bus arrives in seven minutes. How many seconds should its countdown display start with?

Start7 min
Result420
main.rs
fn main() {
    let wait = std::time::Duration::from_secs(7 * 60);
    println!("{}", wait.as_secs());
}
Output
420

A classroom quiz lasts three minutes. What is its time limit in seconds?

Start3 min
Result180
main.rs
fn main() {
    let wait = std::time::Duration::from_secs(3 * 60);
    println!("{}", wait.as_secs());
}
Output
180

A kitchen timer rings after five minutes. How many seconds is that?

Start5 min
Result300
main.rs
fn main() {
    let wait = std::time::Duration::from_secs(5 * 60);
    println!("{}", wait.as_secs());
}
Output
300
Run the example
Terminal
rustc main.rs
./main
Official documentation