如何检索后设置为从CMD日期 [英] How to set date from cmd after retrieving it
本文介绍了如何检索后设置为从CMD日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下的code
set x=%date /T %
date 16/12/2012
date 15/12/2012
some stuff goes here
echo set your date
date %x% <--- getting error in that line.
pause
所以,我怎么能得到格式DD / MM / YY日期
So how can i get the date in the format dd/mm/yy
推荐答案
您可以使用 WMIC
命令获取DD / MM / YY日期格式。这个命令可以让你得到当前的日期而不会受到区域设置。
You can get the date format of dd/mm/yy by using wmic
command. This command allows you to get current date without getting affected by regional settings.
@echo off
SETLOCAL EnableDelayedExpansion
for /f "skip=1 tokens=1-6 delims= " %%a in ('wmic path Win32_LocalTime Get Day^,Hour^,Minute^,Month^,Second^,Year /Format:table') do (
IF NOT "%%~f"=="" (
set /a FormattedDate=10000 * %%f + 100 * %%d + %%a
set FormattedDate=!FormattedDate:~-2,2!/!FormattedDate:~-4,2!/!FormattedDate:~-6,2!
)
)
echo %FormattedDate%
PAUSE
您可以将其保存为 date.bat
,并通过执行运行这个批处理文件在命令提示符下以下内容:
You can save it as date.bat
and run this batch file by executing the following in command prompt:
C:\>date.bat
21/01/13
Press any key to continue...
希望这有助于。
这篇关于如何检索后设置为从CMD日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文