date_str!() { /* proc-macro */ }Expand description
Returns the compile date as &'static str in yyyy-MM-dd format.
By default, the returned date is in UTC, call date_str!(local)
to return the local date.
ยงExample
Get the UTC date:
const COMPILE_DATE: time::Date = compile_time::date!();
let year = COMPILE_DATE.year();
let month: u8 = COMPILE_DATE.month().into();
let day = COMPILE_DATE.day();
let date_string = format!("{year:04}-{month:02}-{day:02}");
assert_eq!(compile_time::date_str!(), date_string);Get the date for the local time zone:
const COMPILE_DATE: time::Date = compile_time::date!(local);
let year = COMPILE_DATE.year();
let month: u8 = COMPILE_DATE.month().into();
let day = COMPILE_DATE.day();
let date_string = format!("{year:04}-{month:02}-{day:02}");
assert_eq!(compile_time::date_str!(local), date_string);