#instant #web #time #systemtime


Drop-in replacement for std::time for Wasm in browsers

2 unstable releases

0.2.0 Mar 28, 2023
0.1.0 Mar 27, 2023

#95 in WebAssembly

Download history 2770/week @ 2023-06-08 1887/week @ 2023-06-15 1942/week @ 2023-06-22 2256/week @ 2023-06-29 3289/week @ 2023-07-06 1811/week @ 2023-07-13 1937/week @ 2023-07-20 2620/week @ 2023-07-27 2197/week @ 2023-08-03 3310/week @ 2023-08-10 5430/week @ 2023-08-17 5657/week @ 2023-08-24 8021/week @ 2023-08-31 13054/week @ 2023-09-07 10051/week @ 2023-09-14 5640/week @ 2023-09-21

37,649 downloads per month
Used in 51 crates (11 directly)


202 lines


Crates.io Version Live Build Status Docs.rs Documentation Main Documentation


Complete drop-in replacement for std::time that works in the browser.

Currently Instant::now() and SystemTime::now() will simply panic when using the wasm32-unknown-unknown target. This implementation uses Performance.now() for Instant and Date.now() for SystemTime to offer a drop-in replacement that works in the browser.

At the same time the library will simply re-export std::time when not using the wasm32-unknown-unknown target and will also not pull in any dependencies.

Additionally, if compiled with target-feature = "atomics" it will synchronize the timestamps to account for different context's, like web workers. See Performance.timeOrigin for more information.


This library specifically targets browsers, that support Performance.now(), with the wasm32-unknown-unknown target. Emscripten is not supported. WASI doesn't require support as it has it's own native API to deal with std::time.

Furthermore it depends on wasm-bindgen, which is required. This library will continue to depend on it until a viable alternative presents itself, in which case multiple ecosystems could be supported.


Currently a known bug is affecting browsers on operating system other then Windows. This bug prevents Instant from continuing to tick when the context is asleep. This doesn't necessarily conflict with Rusts requirements of Instant, but might still be unexpected.

See the MDN documentation on this for more information.


You can simply import the types you need:

use web_time::{Instant, SystemTime};

let now = Instant::now();
let time = SystemTime::now();


As this library heavily relies on wasm-bindgen the MSRV depends on it. At the point of time this was written the MSRV is 1.56.


instant Crates.io is a popular alternative! However the API it implements doesn't match std::time exactly.


See the CHANGELOG file for details.


Inspiration was taken from the instant project.

Additional insight was taken from the time project.


Licensed under either of

at your option.

A majority of the code and documentation was taken from std::time. For license information see #License.


Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.