真的很难!
不过还是做出来了,纯批的,适用多种情况
- @echo off&setlocal enabledelayedexpansion
- set n=1
- for /f "tokens=2 delims=:" %%a in ('echo^;^|date') do (set str!n!=%%a&set/a n+=1)
- set str2=!str2:~2,-2!
- for %%a in (!str1!) do (set var=%%a
- if "!var:-=!" neq "!var!" set fen=-&set str=%%a
- if "!var:/=!" neq "!var!" set fen=/&set str=%%a
-
- )
- set n=3
- for %%a in (!str2:%fen%^= !) do (set str!n!=%%a&set/a n+=1)
- set n=3
- if not defined str4 for %%a in (0 1 2) do (set str!n!=!str2:~%%a,1!&set/a n+=1)
- set n=3
- for %%a in (!str:%fen%^= !) do (
- for %%b in (str!n!) do (
- set !%%b!=%%a&set/a n+=1
- )
- )
-
- for %%a in ("年 月 日" "yyyy mm dd" "yy mm dd") do (
- for /f "tokens=1,2,3" %%b in (%%a) do (
- if defined %%b (
- for /f "tokens=1,2,3" %%e in ("!%%b! !%%c! !%%d!") do (
- endlocal&setlocal enabledelayedexpansion
- set #y=%%e
- set #m=%%f
- set #d=%%g
- ))
- )
- )
-
- :loop
- set in=
- set str=
- set/p in=输入日期格式:
- for %%a in (y m d) do (set in=!in:%%a=" "%%a" "!)
- set/a .y=0,.m=0,.d=0
- for %%a in ("!in!") do (
- if defined #%%~a (
- for %%b in (!.%%~a!) do (
- set str=!str!!#%%~a:~%%b,1!
- )
- set/a .%%~a+=1
- ) else (set str=!str!%%~a)
- )
- echo 分解:"!in!"
- echo 处理结果:!str!
- goto :loop
复制代码
|