diff --git a/esphome/core/buildinfo.cpp b/esphome/core/buildinfo.cpp index d17bf01124..4726f789a1 100644 --- a/esphome/core/buildinfo.cpp +++ b/esphome/core/buildinfo.cpp @@ -34,5 +34,13 @@ const char *get_config_hash() { time_t get_build_time() { return (time_t) build_time; } +const char *get_build_time_string() { + static char time_str[32]; + time_t bt = get_build_time(); + struct tm *tm_info = localtime(&bt); + strftime(time_str, sizeof(time_str), "%b %d %Y, %H:%M:%S", tm_info); + return time_str; +} + } // namespace buildinfo } // namespace esphome diff --git a/esphome/core/buildinfo.h b/esphome/core/buildinfo.h index cc4656f4dc..664b7985dd 100644 --- a/esphome/core/buildinfo.h +++ b/esphome/core/buildinfo.h @@ -13,6 +13,7 @@ namespace buildinfo { const char *get_config_hash(); time_t get_build_time(); +const char *get_build_time_string(); } // namespace buildinfo } // namespace esphome diff --git a/esphome/core/config.py b/esphome/core/config.py index 3adaf7eb9e..f7a5305144 100644 --- a/esphome/core/config.py +++ b/esphome/core/config.py @@ -501,7 +501,7 @@ async def to_code(config: ConfigType) -> None: config[CONF_NAME], config[CONF_FRIENDLY_NAME], config.get(CONF_COMMENT, ""), - cg.RawExpression('__DATE__ ", " __TIME__'), + cg.RawExpression("esphome::buildinfo::get_build_time_string()"), config[CONF_NAME_ADD_MAC_SUFFIX], ) )