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 theDurationstruct from thestd::timemodule.let milliseconds = 1000: creates a variablemillisecondswith the value of 1000.let duration = Duration::from_millis(milliseconds): creates aDurationobject from themillisecondsvariable.
Helpful links
Related
More of Rust
- How to convert a Rust slice of u8 to u32?
- Regex example to match multiline string in Rust?
- How to use regex captures in Rust?
- How to use regex to match a double quote in Rust?
- How to perform matrix operations in Rust?
- How to print a Rust HashMap?
- How to use binary regex in Rust?
- How to extend a Rust HashMap?
- How to match the end of a line in a Rust regex?
- How to use regex to match a group in Rust?
See more codes...