我使用以下格式的日期列输入数据:
MM/DD/YYYY H:M:S
我正在尝试将其更改为:
YYYY/MM/DD H:M:S
如果可能,我想在.bat文件中执行此操作。
编辑,这是Endoro的答案:
set "mydate=MM/DD/YYYY H:M:S"
for /f "tokens=1-4 delims=/ " %%i in (txt) do (
set "month=%%i"
set "day=%%j"
set "year=%%k"
set "mytime=%%l"
)
set "newtime=%year%/%month%/%day% %mytime%"
echo %newtime%
让我添加我想在逗号分隔的文本文件中执行此操作,如果这有帮助。
编辑:前两行文件:
05/20/2013 11:00:28,1,048392,3.17,98%,4.8,13.3,50.7,29.2,29.9,29.2,2
05/20/2013 12:00:22,1,048392,3.17,98%,4.8,13.3,50.4,31.6,36,31.4,3
答案 0 :(得分:2)
您还可以使用for /f
循环:
@echo off&setlocal
set "mydate=MM/DD/YYYY H:M:S"
for /f "tokens=1-4 delims=/ " %%i in ("%mydate%") do (
set "month=%%i"
set "day=%%j"
set "year=%%k"
set "mytime=%%l"
)
set "newtime=%year%/%month%/%day% %mytime%"
echo %newtime%
..输出是:
YYYY/MM/DD H:M:S
答案 1 :(得分:0)
set "dat1=MM/DD/YYYY h:m:s"
set "dat2=%dat1:~6,4%/%dat1:~0,3%%dat1:~3,2%%dat1:~10%"
echo %dat1% - %dat2%
答案 2 :(得分:0)
试试这个 - 基于Endoro的代码和您提供的额外信息。
@echo off
for /f "tokens=1,2,3,* delims=/ " %%i in ('type "file.csv"') do (
echo %%k/%%i/%%j %%l
)>"newfile.csv"