如何从 Windows cmd.exe 脚本中获取年月日? [英] How do I get the day month and year from a Windows cmd.exe script?
本文介绍了如何从 Windows cmd.exe 脚本中获取年月日?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从 Windows cmd 脚本中获取当前的月份和年份?我需要将每个值放入一个单独的变量中.
How do I get the current day month and year from inside a Windows cmd script? I need to get each value into a separate variable.
推荐答案
一种独立于语言环境工作的脚本变体.将其放入扩展名为 .cmd 的文本文件中并运行.
A variant of script that works locale-independently. Put it in a text file with .cmd extension and run.
::: Begin set date
for /f "tokens=1-4 delims=/-. " %%i in ('date /t') do (call :set_date %%i %%j %%k %%l)
goto :end_set_date
:set_date
if "%1:~0,1%" gtr "9" shift
for /f "skip=1 tokens=2-4 delims=(-)" %%m in ('echo,^|date') do (set %%m=%1&set %%n=%2&set %%o=%3)
goto :eof
:end_set_date
::: End set date
echo day in 'DD' format is %dd%; month in 'MM' format is %mm%; year in 'YYYY' format is %yy%
变量 %dd%、%mm% 和 %yy% 将分别保留日('DD' 格式)、月('MM' 格式)和年('YYYY' 格式).
The variables %dd%, %mm% and %yy% will keep the day('DD' format), the month('MM' format) and the year('YYYY' format) respectively.
这篇关于如何从 Windows cmd.exe 脚本中获取年月日?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文