Timestamps are provided by the BasicTimePackage (excluded if using a raw Engine) via the timestamp function.

Timestamps are not available under no_std.

The Rust type of a timestamp is std::time::Instant (instant::Instant in WASM builds).

type_of() a timestamp returns "timestamp".

Built-in Functions

The following methods (defined in the BasicTimePackage but excluded if using a raw Engine) operate on timestamps.

elapsed method and propertynonereturns the number of seconds since the timestamp
- operator1) later timestamp
2) earlier timestamp
returns the number of seconds between the two timestamps
+ operatornumber of seconds to addreturns a new timestamp
- operatornumber of seconds to subtractreturns a new timestamp


fn main() {
let now = timestamp();

// Do some lengthy operation...

if now.elapsed > 30.0 {
    print("takes too long (over 30 seconds)!")