![]() |
中国DOS联盟-- 联合DOS 推动DOS 发展DOS --联盟域名:www.cn-dos.net 论坛域名:www.cn-dos.net/forum |
| 游客 | 登录 | 注册 | 会员 | 搜索 | 中国DOS联盟 |
|
中国DOS联盟论坛 现在时间是 2026-08-08 11:20 |
共 47,811 主题排行 / 349,895 发帖 / 今日 0 篇 / 48,253 会员排行 |
| DOS批处理 & 脚本技术(批处理室) » 【共享】时间、日期计算与转换 批函数库 |
| 可打印版本 2,974 / 20 |
| 第1楼 plp626 | 发表于 2008-04-27 02:48 |
| 银牌会员 发帖 1,020 积分 2,278 | |
|
【共享】时间、日期计算与转换 批函数库 英语不好就算了。。。
【转】 Date and Time Functions ---------------------------------------------------------- 2楼 DateToDOW [ Last edited by plp626 on 2008-4-27 at 04:02 AM ] |
|
| 第2楼 plp626 | 发表于 2008-04-27 02:49 |
| 银牌会员 发帖 1,020 积分 2,278 | |
|
DateToDOW
The DateToDOW function returns the day of week number for a given calendar date.. ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :DateToDOW %yy% %mm% %dd% dow :: :: By: Ritchie Lawrence, 2003-04-29. Version 1.1 :: :: Func: Creates a day of week number from a calendar date, where 1 = Mon :: and 7 = Sun. For NT4/2000/XP/2003. :: :: Args: %1 year component to be converted, 2 or 4 digits (by val) :: %2 month component to be converted, leading zero ok (by val) :: %3 day of month to be converted, leading zero ok (by val) :: %4 var to receive day of week number, 1 to 7 (by ref) ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: setlocal ENABLEEXTENSIONS set yy=%1&set mm=%2&set dd=%3 if 1%yy% LSS 200 if 1%yy% LSS 170 (set yy=20%yy%) else (set yy=19%yy%) set /a dd=100%dd%%%100,mm=100%mm%%%100 set /a z=14-mm,z/=12,y=yy+4800-z,m=mm+12*z-3,dow=153*m+2 set /a dow=dow/5+dd+y*365+y/4-y/100+y/400-2472630,dow%%=7,dow+=1 endlocal&set %4=%dow%&goto :EOF ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: Parameters %1 year component to be converted, 2 or 4 digits (by val) %2 month component to be converted, leading zero ok (by val) %3 day of month to be converted, leading zero ok (by val) %4 var to receive day of week number, 1 to 7 (by ref) Return Values See parameters above. Example @echo off & setlocal ENABLEEXTENSIONS call :GetDate y m d call :DateToDOW %y% %m% %d% dow call :DayName %dow% day echo/Today is %day% goto :EOF Remarks The DateToWeek function also returns day of week (in addition to year and month). |
|
| 第3楼 plp626 | 发表于 2008-04-27 02:49 |
| 银牌会员 发帖 1,020 积分 2,278 | |
|
DateToDays
The DateToDays function converts a calendar date to the number of days elapsed since 1970-01-01. ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :DateToDays %yy% %mm% %dd% days :: :: By: Ritchie Lawrence, 2002-09-26. Version 1.0 :: :: Func: Returns the number of days elapsed since 1st January 1970 for a :: given date. For NT4/2000/XP/2003. :: :: Args: %1 year component used to create days, 2 or 4 digits (by val) :: %2 month component used to create days, leading zero ok (by val) :: %3 date of month used to create days, leading zero ok (by val) :: %4 var to receive number of elapsed days (by ref) ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: setlocal ENABLEEXTENSIONS set yy=%1&set mm=%2&set dd=%3 if 1%yy% LSS 200 if 1%yy% LSS 170 (set yy=20%yy%) else (set yy=19%yy%) set /a dd=100%dd%%%100,mm=100%mm%%%100 set /a z=14-mm,z/=12,y=yy+4800-z,m=mm+12*z-3,j=153*m+2 set /a j=j/5+dd+y*365+y/4-y/100+y/400-2472633 endlocal&set %4=%j%&goto :EOF ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: Parameters %1 year component used to create days, 2 or 4 digits (by val) %2 month component used to create days, leading zero ok (by val) %3 date of month used to create days, leading zero ok (by val) %4 var to receive number of elapsed days (by ref) Return Values See parameters above. Example @echo off & setlocal ENABLEEXTENSIONS call :DateToDays 2003 12 31 days echo/Difference between 1970-01-01 and 2003-12-31 is %days% days goto :EOF Remarks Use in conjunction with the DaysToDate function to perform date arithmetic with a resolution of one day. This function is virtually identical to the DateToMJD function except a different reference date (day 0) has been used. The reference date 1970-01-01, allows for interoperability with MinsToDays and SecsToDays which both share the same reference date. Also note many Windows registry dates are stored as seconds elapsed since 1970-01-01 00:00:00 UTC. |
|
| 第4楼 plp626 | 发表于 2008-04-27 02:49 |
| 银牌会员 发帖 1,020 积分 2,278 | |
|
DateToMJD
The DateToMJD function converts a UTC date to a Modified Julian Day. ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :DateToMJD %yy% %mm% %dd% MJD :: :: By: Ritchie Lawrence, 2002-06-15. Version 1.0 :: :: Func: Returns a Modified Julian Day (MJD) from a UTC date. :: Reference date (day 0) is Wednesday 17th November 1858. For :: NT4/2000/XP/2003. :: :: Args: %1 year component used to create MJD, 2 or 4 digits (by val) :: %2 month component used to create MJD, leading zero ok (by val) :: %3 day of month used to create MJD, leading zero ok (by val) :: %4 var to receive MJD (by ref) ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: setlocal ENABLEEXTENSIONS set yy=%1&set mm=%2&set dd=%3 if 1%yy% LSS 200 if 1%yy% LSS 170 (set yy=20%yy%) else (set yy=19%yy%) set /a dd=100%dd%%%100,mm=100%mm%%%100 set /a z=14-mm,z/=12,y=yy+4800-z,m=mm+12*z-3,j=153*m+2 set /a j=j/5+dd+y*365+y/4-y/100+y/400-2432046 endlocal&set %4=%j%&goto :EOF ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: Parameters %1 year component used to create MJD, 2 or 4 digits (by val) %2 month component used to create MJD, leading zero ok (by val) %3 day of month used to create MJD, leading zero ok (by val) %4 var to receive MJD (by ref) Return Values See parameters above. Example @echo off & setlocal ENABLEEXTENSIONS call :DateToMJD 1999 12 31 x echo/The MJD for 1999-12-31 is: %x% goto :EOF Remarks Use this function in conjunction with MJDToDate to perform date arithmetic with a resolution of one day. For example, use MJDToDate to convert a date to an MJD, then add/subtract x number of days and finally convert the result back to a date using DateToMJD. -------------------------------------------------------------------------------- DateToMins The DateToMins function converts a calendar date to the number of minutes elapsed since 1970-01-01 00:00. ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :DateToMins %yy% %mm% %dd% %hh% %mm% result :: :: By: Ritchie Lawrence, updated 2003-04-03. Version 1.1 :: :: Func: Returns the number of elapsed minutes since 1970-01-01 00:00 :: for a given date. For NT4/2K/XP/2003 :: :: Args: %1 years to convert, 2 or 4 digit (by val) :: %2 months to convert, 1/01 to 12, leading zero ok (by val) :: %3 days to convert, 1/01 to 31, leading zero ok (by val) :: %4 hours to convert, 1/01 to 12 for 12hr times (minutes must be :: suffixed by 'a' or 'p', 0/00 to 23 for 24hr clock (by val) :: %5 mins to convert, 00-59 only, suffixed by a/p if 12hr (by val) :: %6 var to receive number of elapsed minutes (by ref) ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: setlocal ENABLEEXTENSIONS set yy=%1&set mm=%2&set dd=%3&set hh=%4&set nn=%5 if 1%yy% LSS 200 if 1%yy% LSS 170 (set yy=20%yy%) else (set yy=19%yy%) set /a dd=100%dd%%%100,mm=100%mm%%%100 set /a z=14-mm,z/=12,y=yy+4800-z,m=mm+12*z-3,j=153*m+2 set /a j=j/5+dd+y*365+y/4-y/100+y/400-2472633 if 1%hh% LSS 20 set hh=0%hh% if {%nn:~2,1%} EQU {p} if "%hh%" NEQ "12" set hh=1%hh%&set/a hh-=88 if {%nn:~2,1%} EQU {a} if "%hh%" EQU "12" set hh=00 if {%nn:~2,1%} GEQ {a} set nn=%nn:~0,2% set /a hh=100%hh%%%100,nn=100%nn%%%100,j=j*1440+hh*60+nn endlocal&set %6=%j%&goto :EOF ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: Parameters %1 years to convert, 2 or 4 digit (by val) %2 months to convert, 1/01 to 12, leading zero ok (by val) %3 days to convert, 1/01 to 31, leading zero ok (by val) %4 hours to convert, 1/01 to 12 for 12hr times (minutes must be suffixed by 'a' or 'p', 0/00 to 23 for 24hr clock (by val) %5 mins to convert, 00-59 only, suffixed by a/p if 12hr (by val) %6 var to receive number of elapsed minutes (by ref) Return Values See parameters above. Example @echo off & setlocal ENABLEEXTENSIONS call :GetDate y m d call :GetTime h m s t call :DateToMins %y% %m% %d% %h% %m% mins echo/Minutes elapsed since 1970-01-01 00:00: %mins% goto :EOF Remarks Use in conjunction with MinsToDate to perform date arithmetic with a resolution of one minute. Date range is from 1970-01-01 00:00 to 6053-01-23 02:07, which gives a range of 0 to 2147483647 or (2^31)-1 minutes [ Last edited by plp626 on 2008-4-27 at 03:23 AM ] |
|
| 第5楼 plp626 | 发表于 2008-04-27 02:51 |
| 银牌会员 发帖 1,020 积分 2,278 | |
|
DateToOrdinal
The DateToOrdinal function returns an ordinal date from a calendar date as described by ISO 8601. ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :DateToOrdinal %yy% %mm% %dd% year doy :: :: By: Ritchie Lawrence, updated 2002-11-22. Version 1.1 :: :: Func: Returns an ISO 8601 Ordinal date from a calendar date. :: For NT4/2000/XP/2003. :: :: Args: %1 year component to be converted, 2 or 4 digits (by val) :: %2 month component to be converted, leading zero ok (by val) :: %3 day of month to be converted, leading zero ok (by val) :: %4 var to receive year, 4 digits (by ref) :: %5 var to receive doy of year, 001 to 366 (by ref) ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: setlocal ENABLEEXTENSIONS set yy=%1&set mm=%2&set dd=%3 if 1%yy% LSS 200 if 1%yy% LSS 170 (set yy=20%yy%) else (set yy=19%yy%) set /a dd=100%dd%%%100,mm=100%mm%%%100 set /a z=14-mm,z/=12,y=yy+4800-z,m=mm+12*z-3,j=153*m+2 set /a j=j/5+dd+y*365+y/4-y/100+y/400-32045 set /a y=yy+4799,k=y*365+y/4-y/100+y/400-31738,o=j-k+1 if %o% LSS 100 set o=0%o%&if %o% LSS 10 set o=00%o% endlocal&set %4=%yy%&set %5=%o%&goto :EOF ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: Parameters %1 year component to be converted, 2 or 4 digits (by val) %2 month component to be converted, leading zero ok (by val) %3 day of month to be converted, leading zero ok (by val) %4 var to receive year, 4 digits (by ref) %5 var to receive day of year, 001 to 366 (by ref) Return Values See parameters above. Example @echo off & setlocal ENABLEEXTENSIONS call :GetDate y m d call :DateToOrdinal %y% %m% %d% year doy echo/Today (as a Ordinal Date) is: %year%-%doy% goto :EOF |
|
| 第6楼 plp626 | 发表于 2008-04-27 02:52 |
| 银牌会员 发帖 1,020 积分 2,278 | |
|
DateToSecs
The DateToSecs function converts a calendar date to the number of seconds elapsed since 1970-01-01 00:00:00. ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :DateToSecs %yy% %mm% %dd% %hh% %nn% %ss% secs :: :: By: Ritchie Lawrence, updated 2002-08-13. Version 1.1 :: :: Func: Returns number of seconds elapsed since 1st January 1970 00:00:00 :: for a given calendar date and time of day. For NT4/2000/XP/2003. :: :: Args: %1 year to convert, 2 or 4 digit (by val) :: %2 month to convert, 1/01 to 12, leading zero ok (by val) :: %3 day of month to convert, 1/01 to 31, leading zero ok (by val) :: %4 hours to convert, 1/01 to 12 for 12hr times (minutes must be :: suffixed by 'a' or 'p', 0/00 to 23 for 24hr clock (by val) :: %5 mins to convert, 00-59 only, suffixed by a/p if 12hr (by val) :: %6 secs to convert, 0-59 or 00-59 (by val) :: %7 var to receive number of elapsed seconds (by ref) ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: setlocal ENABLEEXTENSIONS set yy=%1&set mm=%2&set dd=%3&set hh=%4&set nn=%5&set ss=%6 if 1%yy% LSS 200 if 1%yy% LSS 170 (set yy=20%yy%) else (set yy=19%yy%) set /a dd=100%dd%%%100,mm=100%mm%%%100 set /a z=14-mm,z/=12,y=yy+4800-z,m=mm+12*z-3,j=153*m+2 set /a j=j/5+dd+y*365+y/4-y/100+y/400-2472633 if 1%hh% LSS 20 set hh=0%hh% if {%nn:~2,1%} EQU {p} if "%hh%" NEQ "12" set hh=1%hh%&set/a hh-=88 if {%nn:~2,1%} EQU {a} if "%hh%" EQU "12" set hh=00 if {%nn:~2,1%} GEQ {a} set nn=%nn:~0,2% set /a hh=100%hh%%%100,nn=100%nn%%%100,ss=100%ss%%%100 set /a j=j*86400+hh*3600+nn*60+ss endlocal&set %7=%j%&goto :EOF ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: Parameters %1 year to convert, 2 or 4 digit (by val) %2 month to convert, 1/01 to 12, leading zero ok (by val) %3 day of month to convert, 1/01 to 31, leading zero ok (by val) %4 hours to convert, 1/01 to 12 for 12hr times (minutes must be suffixed by 'a' or 'p', 0/00 to 23 for 24hr clock (by val) %5 mins to convert, 00-59 only, suffixed by a/p if 12hr (by val) %6 secs to convert, 0-59 or 00-59 (by val) %7 var to receive number of elapsed seconds (by ref) Return Values See parameters above. Example @echo off & setlocal ENABLEEXTENSIONS call :GetDate y m d call :GetTime h n s t call :DateToSecs %y% %m% %d% %h% %n% %s% secs echo/%secs% seconds have elapsed since 1970-01-01 00:00:00 goto :EOF Remarks Use in conjunction with the SecsToDate function to perform date arithmetic with a resolution of one second. Note many Windows registry dates are stored as seconds elapsed since 1970-01-01 00:00:00 UTC. Date range is from 1970-01-01 00:00:00 to 2038-01-19 03:14:07 which gives a range of 0 to 2147483647 or (2^31)-1 seconds. |
|
| 第7楼 plp626 | 发表于 2008-04-27 02:52 |
| 银牌会员 发帖 1,020 积分 2,278 | |
|
DateToWeek
The DateToWeek function returns an ISO 8601 Week date from a calendar date. ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :DateToWeek %yy% %mm% %dd% yn cw dw :: :: By: Ritchie Lawrence, Updated 2002-11-20. Version 1.1 :: :: Func: Returns an ISO 8601 Week date from a calendar date. :: For NT4/2000/XP/2003. :: :: Args: %1 year component to be converted, 2 or 4 digits (by val) :: %2 month component to be converted, leading zero ok (by val) :: %3 day of month to be converted, leading zero ok (by val) :: %4 var to receive year, 4 digits (by ref) :: %5 var to receive calendar week, 2 digits, 01 to 53 (by ref) :: %6 var to receive day of week, 1 digit, 1 to 7 (by ref) ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: setlocal ENABLEEXTENSIONS set yy=%1&set mm=%2&set dd=%3 if 1%yy% LSS 200 if 1%yy% LSS 170 (set yy=20%yy%) else (set yy=19%yy%) set /a dd=100%dd%%%100,mm=100%mm%%%100 set /a z=14-mm,z/=12,y=yy+4800-z,m=mm+12*z-3,Jd=153*m+2 set /a Jd=Jd/5+dd+y*365+y/4-y/100+y/400-32045 set /a y=yy+4798,Jp=y*365+y/4-y/100+y/400-31738,t=Jp+3,Jp=t-t%%7 set /a y=yy+4799,Jt=y*365+y/4-y/100+y/400-31738,t=Jt+3,Jt=t-t%%7 set /a y=yy+4800,Jn=y*365+y/4-y/100+y/400-31738,t=Jn+3,Jn=t-t%%7 set /a Jr=%Jp%,yn=yy-1,yn+=Jd/Jt,yn+=Jd/Jn if %Jd% GEQ %Jn% (set /a Jr=%Jn%) else (if %Jd% GEQ %Jt% set /a Jr=%Jt%) set /a diff=Jd-Jr,cw=diff/7+1,wd=diff%%7,wd+=1 if %cw% LSS 10 set cw=0%cw% endlocal&set %4=%yn%&set %5=%cw%&set %6=%wd%&goto :EOF ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: Parameters %1 year component to be converted, 2 or 4 digits (by val) %2 month component to be converted, leading zero ok (by val) %3 day of month to be converted, leading zero ok (by val) %4 var to receive year, 4 digits (by ref) %5 var to receive calendar week, 2 digits, 01 to 53 (by ref) %6 var to receive day of week, 1 digit, 1 to 7 (by ref) Return Values See parameters above. Example @echo off & setlocal ENABLEEXTENSIONS call :GetDate y d m call :DateToWeek %y% %m% %d% yn cw dw echo/Today (in ISO 8601 Week Date format) is: %yn%-W%cw%-%dw% goto :EOF Remarks None. |
|
| 第8楼 plp626 | 发表于 2008-04-27 02:52 |
| 银牌会员 发帖 1,020 积分 2,278 | |
|
DayName
The DayName function returns the name of the day of week from the day of week number. ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :DayName %d% day :: :: By: Ritchie Lawrence, 2002-10-04. Version 1.0 :: :: Func: Returns the day of week from the day number, 1=Monday, 7=Sunday. :: For NT4/2000/XP/2003. :: :: Args: %1 day number to convert to name of day of week, 1 to 7 (by val) :: %2 var to receive name of day of week (by ref) ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: setlocal ENABLEEXTENSIONS for /f "tokens=%1" %%a in ('echo/Monday Tuesday Wednesday Thursday Friday^ Saturday Sunday') do endlocal&set %2=%%a&goto :EOF ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: Parameters %1 day number to convert to name of day of week, 1 to 7 (by val) %2 var to receive name of day of week (by ref) Return Values The return value is the full name of the day of week, with the first letter capitalised. It can be shortened to the first three letters using substring expansion, for example:- set day=%day:~0,3% Example @echo off & setlocal ENABLEEXTENSIONS call :DayName 3 day echo/Third day of the week is: %day% goto :EOF Remarks Day 1 is Monday, day 7 is Sunday. |
|
| 第9楼 plp626 | 发表于 2008-04-27 02:52 |
| 银牌会员 发帖 1,020 积分 2,278 | |
|
DayNumber
The DayNumber function returns the number of the day of week from the day of week name. ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :DayNumber %Weekday% dow :: :: By: Ritchie Lawrence, 2003-05-14. Version 1.0 :: :: Func: Returns the day number from the name of weekday. Case insensitive :: and only the first three letters are matched, result is 1 to 7 or :: NULL if no match. For NT4/2000/XP/2003. :: :: Args: %1 Weekday name to convert to day of week number (by val) :: %2 var to receive DOW number (by ref) ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: setlocal ENABLEEXTENSIONS & set i=0 for %%a in (Mon Tue Wed Thu Fri Sat Sun) do ( set /a i+=1 & echo/%1|findstr /i /b "%%a" >nul && call set dow=%%i%%) endlocal&set %2=%dow%&goto :EOF ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: Parameters %1 Weekday name to convert to day of week number (by val) %2 var to receive DOW number (by ref) Return Values Function is case insensitive and only the first three letters of the day of week name are required. For example, if called with Wed, wed or Wednesday, the result is 3. If the day of week name is invalid, the return value is NULL. Example @echo off & setlocal ENABLEEXTENSIONS call :DayNumber Tueday dow echo/Tuesday is day: %dow% goto :EOF Remarks Monday is day 1 and Sunday day 7. |
|
| 第10楼 plp626 | 发表于 2008-04-27 02:53 |
| 银牌会员 发帖 1,020 积分 2,278 | |
|
DaysToDate
The DaysToDate function converts the number of days elapsed since 1970-01-01 to a calendar date. ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :DaysToDate %days% yy mm dd :: :: By: Ritchie Lawrence, 2002-06-15. Version 1.1 :: :: Func: Returns a calendar date from the number of elapsed days since :: 1st January 1970. For NT4/2000/XP/2003. :: :: Args: %1 number of days used to create calendar date (by val) :: %2 var to receive year component, 4 digits (by ref) :: %3 var to receive month component, 2 digits, 01-12 (by ref) :: %4 var to receive day of month component, 2 digits, 01-31 (by ref) ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: setlocal ENABLEEXTENSIONS set /a a=%1+2472632,b=4*a+3,b/=146097,c=-b*146097,c/=4,c+=a set /a d=4*c+3,d/=1461,e=-1461*d,e/=4,e+=c,m=5*e+2,m/=153,dd=153*m+2,dd/=5 set /a dd=-dd+e+1,mm=-m/10,mm*=12,mm+=m+3,yy=b*100+d-4800+m/10 (if %mm% LSS 10 set mm=0%mm%)&(if %dd% LSS 10 set dd=0%dd%) endlocal&set %2=%yy%&set %3=%mm%&set %4=%dd%&goto :EOF ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: Parameters %1 MJD used to create calendar date (by val) %2 var to receive year component, 4 digits (by ref) %3 var to receive month component, 2 digits, 01-12 (by ref) %4 var to receive day of month component, 2 digits, 01-31 (by ref) Return Values See parameters above. Example @echo off & setlocal ENABLEEXTENSIONS call :DaysToDate 12345 y m d echo/Adding 12345 days to 1970-01-01 gives the date %y%-%m%-%d% goto :EOF Remarks Use in conjunction with DateToDays to perform date arithmetic with a resolution of one day. |
|
| 第11楼 plp626 | 发表于 2008-04-27 02:53 |
| 银牌会员 发帖 1,020 积分 2,278 | |
|
GetDate
The GetDate function obtains the local system date. ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :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/2000/XP/2003. :: :: 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 ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: Parameters %1 variable to receive year, 4 digits (by ref) %2 variable to receive month, 2 digits, 01 to 12 (by ref) %3 variable to receive day of month, 2 digits, 01 to 31 (by ref) Return Values See parameters above. Example @echo off & setlocal ENABLEEXTENSIONS call :GetDate y m d echo/Today is: %y%-%m%-%d% goto :EOF Remarks This function is independant of regional settings on English versions of Windows. For non-English versions of Windows, you will most likely have to modify the last line of the function to reflect the output from the DATE command. For example, in a command prompt type DATE and press enter twice. On a typical French version of Windows the output is:- La date du jour est : 31/01/2007 Entrez la nouvelle date : (jj-mm-aa) On the second line, the "aa" represents the year and "jj" the day of the month, therefore you need to edit the last line of the function so that "yy" becomes "aa" and "dd" becomes "jj", like this:- endlocal&set %1=%aa%&set %2=%mm%&set %3=%jj%&goto :EOF To learn more about this function, see the thread from the alt.msdos.batch.nt newsgroup titled "Formatting a date". |
|
| 第12楼 plp626 | 发表于 2008-04-27 02:54 |
| 银牌会员 发帖 1,020 积分 2,278 | |
|
GetTime
The GetTime function obtains the local system time. ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :GetTime hh nn ss tt :: :: By: Ritchie Lawrence, updated 2007-05-12. Version 1.3 :: :: Func: Loads local system time components into args 1 to 4. :: For NT4/2000/XP/2003 :: :: Args: %1 Var to receive hours, 2 digits, 00 to 23 (by ref) :: %2 Var to receive minutes, 2 digits, 00 to 59 (by ref) :: %3 Var to receive seconds, 2 digits, 00 to 59 (by ref) :: %4 Var to receive centiseconds, 2 digits, 00 to 99 (by ref) ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: setlocal ENABLEEXTENSIONS for /f "tokens=5-8 delims=:,. " %%a in ('echo/^|time') do ( set hh=%%a&set nn=%%b&set ss=%%c&set cs=%%d) if 1%hh% LSS 20 set hh=0%hh% endlocal&set %1=%hh%&set %2=%nn%&set %3=%ss%&set %4=%cs%&goto :EOF ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: Parameters %1 Var to receive hours, 2 digits, 00 to 23 (by ref) %2 Var to receive minutes, 2 digits, 00 to 59 (by ref) %3 Var to receive seconds, 2 digits, 00 to 59 (by ref) %4 Var to receive centiseconds, 2 digits, 00 to 99 (by ref) Return Values See parameters above. Example @echo off & setlocal ENABLEEXTENSIONS call :GetTime h n s t echo/Time is: %h%:%n%:%s% goto :EOF Remarks This function is independant of regional settings on English versions of Windows. Update: Added a comma to the delims statement - thanks to 'Alvydas'. |
|
| 第13楼 plp626 | 发表于 2008-04-27 02:54 |
| 银牌会员 发帖 1,020 积分 2,278 | |
|
MJDToDate
The MJDToDate function converts a Modified Julian Day to a UTC date. ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :MJDToDate %MJD% yy mm dd :: :: By: Ritchie Lawrence, 2002-06-15. Version 1.1 :: :: Func: Returns a UTC date from a Modified Julian Day (MJD). Reference :: date (day 0) is Wednesday 17th November 1858. :: For NT4/2000/XP/2003. :: :: Args: %1 MJD used to create calendar date (by val) :: %2 var to receive year component, 4 digits (by ref) :: %3 var to receive month component, 2 digits, 01-12 (by ref) :: %4 var to receive day of month, 2 digits, 01-31 (by ref) ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: setlocal ENABLEEXTENSIONS set /a a=%1+2432045,b=4*a+3,b/=146097,c=-b*146097,c/=4,c+=a set /a d=4*c+3,d/=1461,e=-1461*d,e/=4,e+=c,m=5*e+2,m/=153,dd=153*m+2,dd/=5 set /a dd=-dd+e+1,mm=-m/10,mm*=12,mm+=m+3,yy=b*100+d-4800+m/10 (if %mm% LSS 10 set mm=0%mm%)&(if %dd% LSS 10 set dd=0%dd%) endlocal&set %2=%yy%&set %3=%mm%&set %4=%dd%&goto :EOF ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: Parameters %1 MJD used to create calendar date (by val) %2 var to receive year component, 4 digits (by ref) %3 var to receive month component, 2 digits, 01-12 (by ref) %4 var to receive day of month, 2 digits, 01-31 (by ref) Return Values See parameters above. Example @echo off & setlocal ENABLEEXTENSIONS call :MJDToDate 55555 y m d echo/MJD 55555 is %y%-%m%-%d% (Christmas day!) Remarks Use this function in conjunction with DateToMJD to perform date arithmetic with a resolution of one day. For example, use DateToMJD to convert a date to an MJD, then add/subtract days and finally convert back to a date using MJDToDate. |
|
| 第14楼 plp626 | 发表于 2008-04-27 02:54 |
| 银牌会员 发帖 1,020 积分 2,278 | |
|
MinsToDate
The MinsToDate function converts the number of minutes elapsed since 1970-01-01 00:00 to a calendar date and time. ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :MinsToDate %mins% yy mm dd hh nn :: :: By: Ritchie Lawrence, updated 2003-07-13. Version 1.1 :: :: Func: Returns a calendar date and time of day from the number of :: elapsed minutes since 1st January 1970 00:00. :: For NT4/2000/XP/2003. :: :: Args: %1 minutes used to create calendar date and time of day (by val) :: %2 var to receive year, 4 digits for all typical dates (by ref) :: %3 var to receive month, 2 digits, 01 to 12 (by ref) :: %4 var to receive day of month, 2 digits, 01 to 31 (by ref) :: %5 var to receive hours, 2 digits, 00 to 23 (by ref) :: %6 var to receive minutes, 2 digits, 00 to 59 (by ref) ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: setlocal ENABLEEXTENSIONS set /a i=%1,nn=i%%60,i/=60,hh=i%%24,dd=i/24,i/=24 set /a a=i+2472632,b=4*a+3,b/=146097,c=-b*146097,c/=4,c+=a set /a d=4*c+3,d/=1461,e=-1461*d,e/=4,e+=c,m=5*e+2,m/=153,dd=153*m+2,dd/=5 set /a dd=-dd+e+1,mm=-m/10,mm*=12,mm+=m+3,yy=b*100+d-4800+m/10 (if %mm% LSS 10 set mm=0%mm%)&(if %dd% LSS 10 set dd=0%dd%) (if %hh% LSS 10 set hh=0%hh%)&(if %nn% LSS 10 set nn=0%nn%) endlocal&set %6=%nn%&set %5=%hh%&set %4=%dd%&^ set %3=%mm%&set %2=%yy%&goto :EOF ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: Parameters %1 minutes used to create calendar date and time of day (by val) %2 var to receive year, 4 digits for all typical dates (by ref) %3 var to receive month, 2 digits, 01 to 12 (by ref) %4 var to receive day of month, 2 digits, 01 to 31 (by ref) %5 var to receive hours, 2 digits, 00 to 23 (by ref) %6 var to receive minutes, 2 digits, 00 to 59 (by ref) Return Values See parameters above. Example @echo off & setlocal ENABLEEXTENSIONS call :GetDate y m d call :GetTime h n s t call :DateToMins %y% %m% %d% %h% %n% mins set /a mins+=15 call :MinsToDate %mins% y m d h n echo/Date and time in 15 minutes: %y%-%m%-%d% %h%:%n% goto :EOF Remarks Use in conjunction with DateToMins to perform date arithmetic with a resolution of one minute. Range is from 0 to 2147483647 or (2^31)-1 minutes, which gives a date range from 1970-01-01 00:00 to 6053-01-23 02:07. |
|
| 第15楼 plp626 | 发表于 2008-04-27 02:54 |
| 银牌会员 发帖 1,020 积分 2,278 | |
|
MonthName
The MonthName function returns the name of month from the month number. ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :MonthName %mm% month :: :: By: Ritchie Lawrence, 2002-10-04. Version 1.0 :: :: Func: Returns the name of month from the number of the month. :: For NT4/2000/XP/2003. :: :: Args: %1 month number convert to name of month, 1 or 01 to 12 (by val) :: %2 var to receive name of month (by ref) ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: setlocal ENABLEEXTENSIONS&set /a m=100%1%%100 for /f "tokens=%m%" %%a in ('echo/January February March April May June^ July August September October November December' ) do endlocal&set %2=%%a&goto :EOF ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: Parameters %1 month number convert to name of month, 1 or 01 to 12 (by val) %2 var to receive name of month (by ref) Return Values See parameters above. Example @echo off & setlocal ENABLEEXTENSIONS call :GetDate yy mm dd call :MonthName %mm% month echo/The current month is: %month% goto :EOF Remarks The returned month name is the full name of the month with the first letter capitalised. |
|
| 1 2 下一页 |
|
[ 联系联盟系统管理团队 -
中国DOS联盟 -
标准版 ] Sponsored by ifanr Inc | © 2001–2023 |