0

我有数据流以这种格式的日期列:

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
4

3 回答 3

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
于 2013-06-04T19:03:18.913 回答
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%
于 2013-06-04T18:57:27.127 回答
0

试试这个 - 基于 Endoro 的代码和您提供的额外信息。

@echo off
for /f "tokens=1,2,3,* delims=/ " %%i in ('type "file.csv"') do (
echo %%k/%%i/%%j %%l
)>"newfile.csv"
于 2013-06-05T04:46:19.317 回答