Crate time_now

Crate time_now 

Source
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::Duration since UNIX_EPOCH. Uses: std::time. The returned Duration is safe unwrap of Result returned by SystemTime::now().duration_since(UNIX_EPOCH). The unwrap is safe because the UNIX_EPOCH is 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, as f32. Uses: std::time.
now_as_secs_f64
Returns the number of seconds since UNIX_EPOCH, as f64. Uses: std::time.