2013-02-21 63 views
0

之前我養我的查詢,讓我告訴我是新來的批處理文件..轉換系統日期,以DD/MM/YYYY

我在哪裏,我想系統日期,以DD/MM轉換的要求/ YYYY格式,有人可以幫我嗎?

+0

我曾嘗試以下代碼:FOR/F 「令牌= 1,2 DELIMS =/EOL = /」 %% A IN( '日期/ T')DO SET毫米= %%對於/ F「TOKENS = 1,2 DELIMS =/eol = /」%% A IN('echo%CDATE%')DO SET dd = %% B FOR/F「TOKENS = 2,3 DELIMS = 「%% A IN('echo%CDATE%')DO SET yyyy = %% B如果我的系統日期是02/21/2013,我將獲得21/02/2013的輸出。在日期和月份之後會有一個額外的空間 – 2013-02-21 11:57:22

+0

也許在每種情況下,空間都在'SET'語句中的'%% B'之後。像這樣使用雙引號:'SET「mm = %% B」'。 – 2013-03-03 00:43:03

回答

1

這應該可以做到。

http://www.commandline.co.uk/cmdfuncs/dandt/index.html#getdate

@echo off 
call :GetDate year month day 
echo/Today is: %day%-%month%-%year% 
goto :EOF 

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 
:GetDate yy mm dd 
:: 
:: By: Ritchie Lawrence, 2002-06-15. Version 1.0 
:: 
:: Func: Loads local system date components into args 1 to 3. For NT4/2K/XP 
:: 
:: Args: %1 var to receive year, 4 digits (by ref) 
::  %2 var to receive month, 2 digits, 01 to 12 (by ref) 
::  %3 Var to receive day of month, 2 digits, 01 to 31 (by ref) 
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 
setlocal ENABLEEXTENSIONS 
set t=2&if "%date%z" LSS "A" set t=1 
for /f "skip=1 tokens=2-4 delims=(-)" %%a in ('echo/^|date') do (
    for /f "tokens=%t%-4 delims=.-/ " %%d in ('date/t') do (
    set %%a=%%d&set %%b=%%e&set %%c=%%f)) 
endlocal&set %1=%yy%&set %2=%mm%&set %3=%dd%&goto :EOF 
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::