批处理生成带编译日期的头文件()

 1 ::------------start   date time-----------
 2 @SET BUILD_INFO_FILE=components\include\build_info.h
 3 
 4 @echo off
 5 for /f "tokens=1-3 delims=-/. " %%j in ('Date /T') do (
 6 
 7     set year=%%j
 8     set month=%%k
 9     set day=%%l
10 )
11 
12 @echo off
13 for /f "tokens=1,2 delims=: " %%j in ('TIME /T') do (
14 
15     set hour=%%j
16     set minute=%%k
17 )
18 
19 @set today=%year%%month%%day%
20 @set time_now=%hour%:%minute%
21 @echo #ifndef __BUILD_INFO_H__  > %~dp0\%BUILD_INFO_FILE%22 @echo #define __BUILD_INFO_H__  >> %~dp0\%BUILD_INFO_FILE%23 @echo #define  BUILD_DATE  %today% >> %~dp0\%BUILD_INFO_FILE%24 ::@echo #define  BUILD_TIME  "%time_now%" >> %~dp0\%BUILD_INFO_FILE%
25 @echo #endif  >> %~dp0\%BUILD_INFO_FILE%26 
27 @echo build : %today%  %time_now%
28 
29 ::------------end   date time--------------

       如上,在批处理中,生成包含编译日期,时间的头文件   build_info.h,在主程序中,引用此头文件,

就可以获取编译日期,时间。

————————
 1 ::------------start   date time-----------
 2 @SET BUILD_INFO_FILE=components\include\build_info.h
 3 
 4 @echo off
 5 for /f "tokens=1-3 delims=-/. " %%j in ('Date /T') do (
 6 
 7     set year=%%j
 8     set month=%%k
 9     set day=%%l
10 )
11 
12 @echo off
13 for /f "tokens=1,2 delims=: " %%j in ('TIME /T') do (
14 
15     set hour=%%j
16     set minute=%%k
17 )
18 
19 @set today=%year%%month%%day%
20 @set time_now=%hour%:%minute%
21 @echo #ifndef __BUILD_INFO_H__  > %~dp0\%BUILD_INFO_FILE%22 @echo #define __BUILD_INFO_H__  >> %~dp0\%BUILD_INFO_FILE%23 @echo #define  BUILD_DATE  %today% >> %~dp0\%BUILD_INFO_FILE%24 ::@echo #define  BUILD_TIME  "%time_now%" >> %~dp0\%BUILD_INFO_FILE%
25 @echo #endif  >> %~dp0\%BUILD_INFO_FILE%26 
27 @echo build : %today%  %time_now%
28 
29 ::------------end   date time--------------

       如上,在批处理中,生成包含编译日期,时间的头文件   build_info.h,在主程序中,引用此头文件,

就可以获取编译日期,时间。