[Windows] BAT 파일에서 현재 시간,날짜 만들기

Stackoverflow에 외국에 맞는게 올라가 있다.

Locale 설정에 따라 달라져야 한다. 맞게 바꾸면.

set hour=%time:~0,2%

if “%hour:~0,1%” == ” ” set hour=0%hour:~1,1%

echo hour=%hour%

set min=%time:~3,2%

if “%min:~0,1%” == ” ” set min=0%min:~1,1%

echo min=%min%

set secs=%time:~6,2%

if “%secs:~0,1%” == ” ” set secs=0%secs:~1,1%

echo secs=%secs%

set year=%date:~0,4%

echo year=%year%

set month=%date:~5,2%

if “%month:~0,1%” == ” ” set month=0%month:~1,1%

echo month=%month%

set day=%date:~8,2%

if “%day:~0,1%” == ” ” set day=0%day:~1,1%

echo day=%day%

set datetimef=%year%%month%%day%_%hour%%min%%secs%

참고: http://stackoverflow.com/questions/1192476/format-date-and-time-in-a-windows-batch-script