中国DOS联盟论坛

中国DOS联盟

-- 联合DOS 推动DOS 发展DOS --

联盟域名:www.cn-dos.net  论坛域名:www.cn-dos.net/forum
DOS,代表着自由开放与发展,我们努力起来,学习FreeDOS和Linux的自由开放与GNU精神,共同创造和发展美好的自由与GNU GPL世界吧!

游客:  注册 | 登录 | 命令行 | 搜索 | 上传 | 帮助 »
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » 【共享】时间、日期计算与转换 批函数库
作者:
标题: 【共享】时间、日期计算与转换 批函数库 上一主题 | 下一主题
plp626
银牌会员

钻石会员


积分 2278
发帖 1020
注册 2007-11-19
状态 离线
『第 16 楼』:  

MonthNumber The MonthNumber function returns the number of a number from a month name. ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :MonthNumber %month% mm :: :: By: Ritchie Lawrence, 2003-05-14. Version 1.0 :: :: Func: Returns the number of month from name of month. Case insensitive :: and only the first three letters are matched, result is 01 to :: 12 or NULL if no match. For NT4/2000/XP/2003. :: :: Args: %1 month name to convert to month number, Jan to Dec (by val) :: %2 var to receive number of month (by ref) ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: setlocal ENABLEEXTENSIONS & set i=0 for %%a in (Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec) do ( set /a i+=1 & echo/%1|findstr /i /b "%%a" >nul && call set mm=%%i%%) (if 1%mm% LSS 110 set mm=0%mm%) & endlocal&set %2=%mm%&goto :EOF ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: Parameters %1 month name to convert to month number, Jan to Dec (by val) %2 var to receive number of month (by ref) Return Values Only the first three letters of the month are required. For example, if called with Apr or April, 4 is returned. This function is case insensitive. If the month name is invalid, NULL is required. Example @echo off & setlocal ENABLEEXTENSIONS call :MonthNumber April mm echo/April is month: %mm% goto :EOF Remarks None.




山外有山,人外有人;低调做人,努力做事。 进入网盘(各种工具)~~ 空间~~cmd学习
2008-4-27 02:55
查看资料  发短消息  网志   编辑帖子  回复  引用回复
plp626
银牌会员

钻石会员


积分 2278
发帖 1020
注册 2007-11-19
状态 离线
『第 17 楼』:  

OrdinalToDate The OrdinalToDate function returns a calendar date from an ISO 8601 Ordinal date. ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :OrdinalToDate %year% %doy% yy mm dd :: :: By: Ritchie Lawrence, 2002-09-29. Version 1.0 :: :: Func: Returns a calendar date from an ISO 8601 Ordinal date. :: For NT4/2000/XP/2003. :: :: Args: %1 year component to be converted, 4 digits (by val) :: %2 day of year component to be converted, 001 to 366 (by val) :: %3 var to receive year, 4 digits (by ref) :: %4 var to receive month, 2 digits, 01 to 31 (by ref) :: %5 var to receive day of month, 01 to 31 (by ref) ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: setlocal ENABLEEXTENSIONS for /f "tokens=1-2" %%a in ('echo/%1 %2') do set /a yy=%%a,o=1%%b%%1000 set /a z=14-1,z/=12,y=yy+4800-z,m=1+12*z-3,j=153*m+2 set /a j=j/5+1+y*365+y/4-y/100+y/400-2432046,j+=o-1 set /a a=j+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 %3=%yy%&set %4=%mm%&set %5=%dd%&goto :EOF ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: Parameters %1 year component to be converted, 4 digits (by val) %2 day of year component to be converted, 001 to 366 (by val) %3 var to receive year, 4 digits (by ref) %4 var to receive month, 2 digits, 01 to 31 (by ref) %5 var to receive day of month, 01 to 31 (by ref) Return Values See parameters above. Example @echo off & setlocal ENABLEEXTENSIONS call :OrdinalToDate 2000 090 y m d echo/The date of the 90th day of the year 2000 is: %y%-%m%-%d% goto :EOF Remarks Note the second parameter (day of year) must be in the range 001 to 366 (not 1 to 366).




山外有山,人外有人;低调做人,努力做事。 进入网盘(各种工具)~~ 空间~~cmd学习
2008-4-27 02:55
查看资料  发短消息  网志   编辑帖子  回复  引用回复
plp626
银牌会员

钻石会员


积分 2278
发帖 1020
注册 2007-11-19
状态 离线
『第 18 楼』:  

SecsToDate The SecsToDate function converts the number of seconds elapsed since 1970-01-01 00:00:00 to a calendar date and time. ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :SecsToDate %secs% yy mm dd hh nn ss :: :: By: Ritchie Lawrence, updated 2002-07-24. Version 1.1 :: :: Func: Returns a calendar date and time of day from the number of :: elapsed seconds since 1st January 1970 00:00:00. For :: NT4/2000/XP/2003. :: :: Args: %1 seconds 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) :: %7 var to receive seconds, 2 digits, 00 to 59 (by ref) ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: setlocal ENABLEEXTENSIONS set /a i=%1,ss=i%%60,i/=60,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%) if %ss% LSS 10 set ss=0%ss% endlocal&set %7=%ss%&set %6=%nn%&set %5=%hh%&^ set %4=%dd%&set %3=%mm%&set %2=%yy%&goto :EOF ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: Parameters %1 seconds 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) %7 var to receive seconds, 2 digits, 00 to 59 (by ref) Return Values See parameters above. Example This example uses REG.EXE v2.0 to extract the InstallDate value (which is stored as seconds elapsed since 1970-01-01 00:00:00) from the Windows Registry. This is then converted to a date and time. Note the second FOR loop avoids having to use a TAB character in the DELIMS statement of the first FOR loop. echo off & setlocal ENABLEEXTENSIONS :: requires REG.EXE Version 2.0 or later set key="HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" set val="InstallDate" for /f "delims=" %%a in ('reg query %key% /v %val%^|find %val%') do ( for %%b in (%%a) do set secs=%%b ) call :SecsToDate %secs% yy mm dd hh nn ss echo/Windows installation date is: %yy%-%mm%-%dd% %hh%:%nn%:%ss% goto :EOF Remarks Use in conjunction with DateToSecs to perform date arithmetic with a resolution of one second. Range is from 0 to 2147483647 or (2^31)-1 seconds which gives a date range from 1970-01-01 00:00:00 to 2038-01-19 03:14:07.




山外有山,人外有人;低调做人,努力做事。 进入网盘(各种工具)~~ 空间~~cmd学习
2008-4-27 02:55
查看资料  发短消息  网志   编辑帖子  回复  引用回复
plp626
银牌会员

钻石会员


积分 2278
发帖 1020
注册 2007-11-19
状态 离线
『第 19 楼』:  

WeekToDate The WeekToDate function returns a calendar date from an ISO 8601 Week date. ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :WeekToDate %yn% %cw% %dw% yy mm dd :: :: By: Ritchie Lawrence, 2002-10-04. Version 1.0 :: :: Func: Returns a calendar date from an ISO 8601 Week date. :: For NT4/2000/XP/2003. :: :: Args: %1 year to convert, 2 or 4 digits (by val) :: %2 calendar week to convert, 2 digits, 01 to 53 (by val) :: %3 day of week to convert, 1 digit, 1 to 7 (by val) :: %4 var to receive year, 4 digits (by ref) :: %5 var to receive month, 2 digits, 01 to 12 (by ref) :: %6 var to receive day of month, 2 digits, 01 to 31 (by ref) ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: setlocal ENABLEEXTENSIONS set yn=%1&set cw=%2&set dw=%3 if 1%yy% LSS 200 if 1%yy% LSS 170 (set yy=20%yy%) else (set yy=19%yy%) set /a cw=100%cw%%%100,d=3210654 set /a z=14-1,z/=12,y=yn+4800-z,m=1+12*z-3,Jt=153*m+2 set /a Jt=Jt/5+1+y*365+y/4-y/100+y/400-32045,wt=Jt%%7 call set at=%%d:~%wt%,1%%&set /a Jt=at+Jt-3 set /a Jt=Jt+7*cw+dw-9,a=Jt+32045,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 %4=%yy%&set %5=%mm%&set %6=%dd%&goto :EOF ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: Parameters %1 year to convert, 2 or 4 digits (by val) %2 calendar week to convert, 2 digits, 01 to 53 (by val) %3 day of week to convert, 1 digit, 1 to 7 (by val) %4 var to receive year, 4 digits (by ref) %5 var to receive month, 2 digits, 01 to 12 (by ref) %6 var to receive day of month, 2 digits, 01 to 31 (by ref) Return Values See parameters above. Example @echo off & setlocal ENABLEEXTENSIONS call :WeekToDate 2000 15 2 yy mm dd echo/The date on day 2 of week 15 of the year 2000 is: %yy%-%mm%-%dd% goto :EOF Remarks None.




山外有山,人外有人;低调做人,努力做事。 进入网盘(各种工具)~~ 空间~~cmd学习
2008-4-27 02:55
查看资料  发短消息  网志   编辑帖子  回复  引用回复
feixueOK
新手上路





积分 2
发帖 1
注册 2008-4-28
状态 离线
『第 20 楼』:  

顶一下!


2008-5-7 10:56
查看资料  发送邮件  发短消息  网志   编辑帖子  回复  引用回复
joyn
中级用户

丶杏灬丶


积分 280
发帖 105
注册 2008-5-6
来自 广西
状态 离线
『第 21 楼』:  

不好用


2008-5-7 13:06
查看资料  发送邮件  发短消息  网志   编辑帖子  回复  引用回复

请注意:您目前尚未注册或登录,请您注册登录以使用论坛的各项功能,例如发表和回复帖子等。


可打印版本 | 推荐给朋友 | 订阅主题 | 收藏主题



论坛跳转: