#time #utc #cross-platform #unixtime #unix-timestamp #no-std

no-std utcnow

Get the current unixtime in a no-std context

13 releases

0.2.5 Mar 18, 2024
0.2.4 Sep 11, 2023
0.2.3 Mar 14, 2023
0.2.2 Nov 24, 2022
0.0.0-pre5 Jul 24, 2022

#39 in Date and time

Download history 1301/week @ 2023-12-23 1895/week @ 2023-12-30 2603/week @ 2024-01-06 2684/week @ 2024-01-13 3397/week @ 2024-01-20 3617/week @ 2024-01-27 4488/week @ 2024-02-03 4513/week @ 2024-02-10 5714/week @ 2024-02-17 5725/week @ 2024-02-24 5054/week @ 2024-03-02 5246/week @ 2024-03-09 4778/week @ 2024-03-16 4308/week @ 2024-03-23 4752/week @ 2024-03-30 3963/week @ 2024-04-06

18,453 downloads per month
Used in 19 crates (2 directly)

Apache-2.0

53KB
964 lines

utcnow — Get the current unixtime in a no-std context

GitHub Workflow Status Crates.io Minimum supported Rust version License

This library solves one question, and one question only: What's the time?

In UTC, and according to the clock of the PC, tablet, toaster … the library runs on, expressed as seconds + nanoseconds since 1970-01-01.

let now = utcnow().unwrap();
let seconds = now.as_secs();
let nanos = now.subsec_nanos();

For many target platforms this call cannot fail. If this is true for the current target, then the constant INFALLIBLE will be true.

If the target platform is not supported, then utcnow() will always return an error instead of failing to compile. Use the library with default-features = false and without the feature fallback to get a compile-time error instead.

The feature std (enabled by default) is only needed if you need the Error type to implement std::error::Error.

Supported platforms

If you have successfully tested one of the untested targets, then please tell me. And if not, then even more so!

If you know how to implement another target, then please open a pull request.

Supported and tested:

  • Android
  • Emscripten
  • FreeBSD
  • Haiku
  • Illumos
  • Linux
  • Linux with Musl
  • MacOS
  • NetBSD
  • WASI
  • wasm32
  • Windows

(Probably) supported, but not actually tested:

  • Darwin
  • Dragonfly
  • Fuchsia
  • iOS
  • OpenBSD
  • Redox
  • Solaris

Increasing the msrv for tier-2 or lower platforms will not be indicated as a breaking change to the semver version.

Feature flags

utcnow has the following optional features:

Dependencies

~0–11MB
~109K SLoC