Skip to main content

datetime

Macro datetime 

Source
datetime!() { /* proc-macro */ }
Expand description

Returns the compile date and time as time::OffsetDateTime.

By default, the returned datetime is in UTC, call datetime!(local) to return the local date and time.

ยงExample

Get the UTC date and time:

const COMPILE_DATETIME: time::OffsetDateTime = compile_time::datetime!();

let year = COMPILE_DATETIME.year();
let month = COMPILE_DATETIME.month();
let day = COMPILE_DATETIME.day();
let hour = COMPILE_DATETIME.hour();
let minute = COMPILE_DATETIME.minute();
let second = COMPILE_DATETIME.second();
println!("Compiled at {hour:02}:{minute:02}:{second:02} on {month} {day}, {year}.");

Get the date and time for the local time zone:

const COMPILE_DATETIME: time::OffsetDateTime = compile_time::datetime!(local);

let year = COMPILE_DATETIME.year();
let month = COMPILE_DATETIME.month();
let day = COMPILE_DATETIME.day();
let hour = COMPILE_DATETIME.hour();
let minute = COMPILE_DATETIME.minute();
let second = COMPILE_DATETIME.second();
println!("Compiled at {hour:02}:{minute:02}:{second:02} on {month} {day}, {year}.");