rustHow to get time from milliseconds in Rust
To get time from milliseconds in Rust, you can use the Duration
struct from the std::time
module. This struct takes a u64
value representing the number of milliseconds and returns a Duration
object.
Example code
use std::time::Duration;
let milliseconds = 1000;
let duration = Duration::from_millis(milliseconds);
Output example
Duration {
secs: 1,
nanos: 0
}
Code explanation
use std::time::Duration
: imports theDuration
struct from thestd::time
module.let milliseconds = 1000
: creates a variablemilliseconds
with the value of 1000.let duration = Duration::from_millis(milliseconds)
: creates aDuration
object from themilliseconds
variable.
Helpful links
Related
More of Rust
- How to match whitespace with a regex in Rust?
- How to match the end of a line in a Rust regex?
- How to perform matrix operations in Rust?
- How to replace strings using Rust regex?
- How to use regex to match a double quote in Rust?
- How to replace a capture group using Rust regex?
- How to split a string with Rust regex?
- How to use regex with bytes in Rust?
- How to convert a Rust HashMap to JSON?
- Bitwise operator example in Rust
See more codes...