Split

后端 未结 9 1370
感情败类
感情败类 2020-11-29 12:37

Is there a way to split the %date% in a batch file (say, in 3 environment variables), but regardless of Regional Settings? Today\'s date would be 3/13/201

9条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-29 12:49

    I have an additional suggestion with robocopy:

    @echo off &setlocal enabledelayedexpansion
    set "day="
    for /f "tokens=3,4,8skip=4delims=: " %%i in ('robocopy') do if not defined day (
        set "month=%%i"
        set "day=0%%j"
        set "year=%%k"
    )
    set /a cnt=0
    for %%i in (Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec) do (
        set /a cnt+=1
        if "%%i"=="%month%" set "month=0!cnt!"
    )
    set "day=%day:~-2%"
    set "month=%month:~-2%"
    echo.%day%.%month%.%year%
    endlocal
    

提交回复
热议问题