timestamp

Macro timestamp 

Source
macro_rules! timestamp {
    () => { ... };
    (milliseconds) => { ... };
    (millis) => { ... };
    (micro) => { ... };
    (micros) => { ... };
    (nano) => { ... };
    (nanos) => { ... };
    ($fmt:literal) => { ... };
    ($unknown:tt) => { ... };
}
Expand description

Local timestamp helper using chrono::Local.

§Usage

  • timestamp!() – seconds precision (default)
  • timestamp!(milliseconds) – millisecond precision
  • timestamp!(millis) – alias for milliseconds
  • timestamp!(micro) / micros – microsecond precision
  • timestamp!(nano) / nanos – nanosecond precision
  • timestamp!("%Y-%m-%d %H:%M") – custom chrono format (string literal)

§Examples

Basic/Default (seconds):

// use log_x::timestamp; // uncomment and replace `your_crate` if you want this to compile
use log_x::timestamp;
println!("{}", timestamp!());
// Output (example): 2025-08-29 10:22:11

Milliseconds:

use log_x::timestamp;
println!("{}", timestamp!(milliseconds));
println!("{}", timestamp!(millis)); // alias
// Output (example): 2025-08-29 10:22:11.123

Microseconds / Nanoseconds:

use log_x::timestamp;
println!("{}", timestamp!(micro));  // Output (example): 2025-08-29 10:22:11.123456
println!("{}", timestamp!(nanos));  // Output (example): 2025-08-29 10:22:11.123456789

Custom format (with timezone offset): for format example and explanations see: https://docs.rs/chrono/latest/chrono/format/strftime/index.html

use log_x::timestamp;
println!("{}", timestamp!("%Y-%m-%d %H:%M:%S %z"));
// Output (example): 2025-08-29 10:22:11 +0200