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
- Regex example to match multiline string in Rust?
- How to map a Rust slice?
- How to push an element to a Rust slice?
- How to match whitespace with a regex in Rust?
- How to replace strings using Rust regex?
- How to create a HashMap of structs in Rust?
- How to sort a Rust HashMap?
- How to convert a u8 slice to a hex string in Rust?
- How to compile a regex in Rust?
- How to use regex captures in Rust?
See more codes...