下面的代码从当前日期获取日期。当然,很容易将其更改为固定年份。
我想说这都是我自己写的,但它是基于Rob van der Woude 的代码。看看网站。它有很多日期计算功能,所有这些功能都隔离在单独的脚本中,而不是我用它制作的固定用途的混乱。;)
@echo off
:: Input: The number of days to add. You can make this a parameter
:: too, if you want.
SET /A Days = 20
echo %DATE:~-4%
:: Get 1 january of the current year
SET /A Year1 = %DATE:~-4% + 4800
SET MM=1
SET DD=1
:: Calculate the Julian date of that date.
SET /A Month1 = ( %MM% - 14 ) / 12
SET /A JDate = 1461 * ( %Year1% + %Month1% ) / 4 + 367 * ( %MM% - 2 -12 * %Month1% ) / 12 - ( 3 * ( ( %Year1% + %Month1% + 100 ) / 100 ) ) / 4 + %DD% - 32075
:: Add the number of days
SET /A JDate = %JDate% + %Days%
:: Calculate it back to year, month and day.
SET /A P = %JDate% + 68569
SET /A Q = 4 * %P% / 146097
SET /A R = %P% - ( 146097 * %Q% +3 ) / 4
SET /A S = 4000 * ( %R% + 1 ) / 1461001
SET /A T = %R% - 1461 * %S% / 4 + 31
SET /A U = 80 * %T% / 2447
SET /A V = %U% / 11
:: SET /A GYear = 100 * ( %Q% - 49 ) + %S% + %V%
SET /A GMonth = %U% + 2 - 12 * %V%
SET /A GDay = %T% - 2447 * %U% / 80
:: Echo only month and day
echo %GMonth% %GDay%
:: Clean-up
FOR %%A IN (P Q R S T U V MM DD JDate Year1 GDay GMonth GYear) DO SET %%A=