将系统日期转换为dd / mm / yyyy

时间:2013-02-21 10:10:43

标签: batch-file

在我提出查询之前,请告诉我我是批处理文件的新手..

我有一个要求,我希望将系统日期转换为DD / MM / YYYY格式,有人可以帮帮我吗?

1 个答案:

答案 0 :(得分: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
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::