Expand description
§time-now
Get current time as seconds or milli/micro/nano seconds, since unix epoch time, using single function call.
Pure Rust std library based. No dependencies on any other crate.
Safe and Lightweight (~2 kb).
§Examples:
use time_now;
fn main() {
println!("time_now::now_as_secs : {:?}", time_now::now_as_secs());
println!(
"time_now::now_as_secs_f32: {:?}",
time_now::now_as_secs_f32()
);
println!(
"time_now::now_as_secs_f64: {:?}",
time_now::now_as_secs_f64()
);
println!("time_now::now_as_millis : {:?}", time_now::now_as_millis());
println!("time_now::now_as_micros : {:?}", time_now::now_as_micros());
println!("time_now::now_as_nanos : {:?}", time_now::now_as_nanos());
println!(
"time_now::duration_since_epoch: {:?}",
time_now::duration_since_epoch()
);
println!("NOTE: Each function calls std::time::SystemTime::now(),
hence each subsequent call will be ahead of time compare to previous call");
}§Stability
Only stable functions have been included.
The Nightly-only experimental APIs (Duration::as_millis_f32() and Duration::as_millis_f64()
have not been included. They’ll be included in future, once they become stable.
Functions§
- duration_
since_ epoch - Returns
std::time::DurationsinceUNIX_EPOCH. Uses:std::time. The returnedDurationis safe unwrap ofResultreturned bySystemTime::now().duration_since(UNIX_EPOCH). The unwrap is safe because theUNIX_EPOCHis earlier than now. - now_
as_ micros - Returns the number of whole microseconds since
UNIX_EPOCH. Uses:std::time. - now_
as_ millis - Returns the number of whole milliseconds since
UNIX_EPOCH. Uses:std::time. - now_
as_ nanos - Returns the number of nanoseconds since
UNIX_EPOCH. Uses:std::time. - now_
as_ secs - Returns the number of whole seconds since
UNIX_EPOCH. Uses:std::time. - now_
as_ secs_ f32 - Returns the number of seconds since
UNIX_EPOCH, asf32. Uses:std::time. - now_
as_ secs_ f64 - Returns the number of seconds since
UNIX_EPOCH, asf64. Uses:std::time.