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
fn main() {
let wait = std::time::Duration::from_secs(2 * 60);
println!("{}", wait.as_secs());
}
120
Advertisements
Everyday examples
The next bus arrives in seven minutes. How many seconds should its countdown display start with?
Start7 min
Result420
fn main() {
let wait = std::time::Duration::from_secs(7 * 60);
println!("{}", wait.as_secs());
}
420
A classroom quiz lasts three minutes. What is its time limit in seconds?
Start3 min
Result180
fn main() {
let wait = std::time::Duration::from_secs(3 * 60);
println!("{}", wait.as_secs());
}
180
A kitchen timer rings after five minutes. How many seconds is that?
Start5 min
Result300
fn main() {
let wait = std::time::Duration::from_secs(5 * 60);
println!("{}", wait.as_secs());
}
300