ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • Windows Batch File (.bat) Date and Time 날짜 시간
    카테고리 없음 2011. 8. 29. 01:34


    파일명에 시간 stamp를 삽입했다.

    헉 그런데 새벽 0시~ 9시사이에 시간정보는 "01" 로 안나오고 " 1" 즉 공백이 포함되어 파일명으로 쓸 수 없었다.
    아래와 같이 하니 공백없이 01로 나와 잘 되었다.

    ::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    ::
    :: This uses Windows Scripting Host to set variables
    :: to the current date/time/day/day_number
    :: for Win9x/ME/NT/W2K/XP etc
    :: Thanks go to Todd Vargo for his scripting
    ::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    @echo off
    set TmpFile=”%temp%.tmp.vbs”
    echo> %TmpFile% n=Now
    echo>>%TmpFile% With WScript
    echo>>%TmpFile% .Echo “set year=” + CStr(Year(n))
    echo>>%TmpFile% .Echo “set yr=” + Right(Year(n),2)
    echo>>%TmpFile% .Echo “set month=”+ Right(100+Month(n),2)
    echo>>%TmpFile% .Echo “set day=” + Right(100+Day(n),2)
    echo>>%TmpFile% .Echo “set hour=” + Right(100+Hour(n),2)
    echo>>%TmpFile% .Echo “set min=” + Right(100+Minute(n),2)
    echo>>%TmpFile% .Echo “set sec=” + Right(100+Second(n),2)
    echo>>%TmpFile% .Echo “set dow=” + WeekDayName(Weekday(n),1)
    echo>>%TmpFile% .Echo “set dow2=” + WeekDayName(Weekday(n))
    echo>>%TmpFile% .Echo “set iso=” + CStr(1 + Int(n-2) mod 7)
    echo>>%TmpFile% .Echo “set iso2=” + CStr(Weekday(n,2))
    echo>>%TmpFile% End With
    cscript //nologo “%temp%.tmp.vbs” > “%temp%.tmp.bat”
    call “%temp%.tmp.bat”
    del “%temp%.tmp.bat”
    del %TmpFile%
    set TmpFile=
    set stamp=%year%-%month%-%day%_%hour%.%min%.%sec%

    echo The year (YYyy) is “%year%”
    echo The year (yy) is “%yr%”
    echo The month is “%month%”
    echo The day (%dow%) is “%day%”
    echo The full weekday name is “%dow2%”
    echo.
    echo ISO 8601 Day-Of-Week number is “%iso%”
    echo.
    echo The hour is “%hour%”
    echo The minute is “%min%”
    echo The second is “%sec%”
    echo.

    echo The date and time stamp is “%stamp%”
    echo.
    echo time (hhmmss) (%hour%%min%%sec%)
    echo.
    echo date A (yyyymmdd) (%year%%month%%day%)
    echo date B (mmddyyyy) (%month%%day%%year%)
    echo date C (ddmmyyyy) (%day%%month%%year%)
    echo.
    echo date D [yymmdd] [%yr%%month%%day%]
    echo date E [mmddyy] [%month%%day%%yr%]
    echo date F [ddmmyy] [%day%%month%%yr%]
    :: datetime.bat
    ::::::::::::::::::::::::::::::::::::::::::::::::::::::::



    출처 : http://www.google.co.kr/url?sa=t&source=web&cd=3&ved=0CEYQFjAC&url=http%3A%2F%2Fwww.tech-recipes.com%2Frx%2F956%2Fwindows-batch-file-bat-to-get-current-date-in-mmddyyyy-format%2F&rct=j&q=bat%20time%20set%20HOUR&ei=c2haTu-sLsnmmAWgl-iyDA&usg=AFQjCNGc_K2X2WLuZxGwg822IsFO258B6w&cad=rjt

Designed by Tistory.