ntime 0.3.0

NanoTime is a lightweight, high-performance Rust library for nanosecond-precision timestamps.
Documentation
  • Coverage
  • 100%
    34 out of 34 items documented1 out of 1 items with examples
  • Size
  • Source code size: 44.42 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.25 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 29s Average build duration of successful builds.
  • all releases: 23s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • plisandro/ntime
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • plisandro

NanoTime

NanoTime is a lightweight, high-performance Rust library for nanosecond-precision timestamps. It offers support for timestamp generation, arithmetics, comparsion and casting to various string representations, in either local or UTC timezones.

NanoTime has no external Rust dependencies, and runs on all Unix and Windows platforms.

Usage

Latest stable release is v0.3.0. To use it, add the ntime crate to your Cargo.toml file:

[dependencies]
ntime = "0.3.0"

Basic examples

NanoTime can resolve timestamps, and serialize them as multiple formats.

let now = Timestamp::now();
println!("current time, as nanos since epoch: {}", now.as_nanos());
println!("current time as debug:              {:?}", now);
println!("current time as string:             {}", now.to_string());
println!("current time (local):               {}", now.as_string(&Format::LocalMillisDateTime));
println!("current time (UTC):                 {}", now.as_string(&Format::UtcRFC7231));
current time, as nanos since epoch:  1774369621732000558
current time as debug:               Timestamp { seconds: 1774369621, nanoseconds: 732000558 },
current time as string:              2026-03-24 17:21:01 +0100
current time (local):                2026-03-24 17:27:01.732 +0100
current time (UTC):                  Tue, 24 Mar 2026 16:27:01 UTC

It can also compute durations between timestamps. And it's blazing fast, too - see the benchmarks page for details - with lock time being dictated mostly by (g)libc calls.

let start = Timestamp::now();
start.write(&mut io::empty(), &Format::UtcMillisDateTime).expect("oh no the write failed");
println!("wrote a serialized timestamp in {elapsed:?}", elapsed = Timestamp::now() - start);
wrote a serialized timestamp in 21ns.

Limitations

  • NanoTime is intended mainly to deal with precision timestamps. If you need date/time management with full support for timezone and calendar operations, see Chrono instead.
  • Windows support is partial, and under developement.

Documentation

License

NanoTime is distrubuted under the MIT license.