标题: [日期时间] 取前一天日期建文件夹名的批处理为何出错? [打印本页]
作者: zf0111_2000 时间: 2013-9-3 08:27 标题: 取前一天日期建文件夹名的批处理为何出错?
- @echo on
- setlocal enabledelayedexpansion
- set curr_year=%date:~0,4%
- set curr_month=%date:~5,2%
- set curr_day=%date:~8,2%
-
- if %curr_month:~0,1%==0 set curr_month=%curr_month:~1,1%
- if %curr_day:~0,1%==0 set curr_day=%curr_day:~1,1%
-
- set last_year=%curr_year%
- set tmp_last_month=%curr_month%
- set /a tmp_last_day=%curr_day%-1
-
- if %tmp_last_day%==0 set /a tmp_last_month=%curr_month%-1
-
- if !tmp_last_day!==0 (
- if !tmp_last_month!==0 (
- set last_day=31
- goto final
- )
- if !tmp_last_month!==1 (
- set last_day=31
- goto final
- )
- if !tmp_last_month!==2 (
- goto leap_year
- )
- if !tmp_last_month!==3 (
- set last_day=31
- goto final
- )
- if !tmp_last_month!==4 (
- set last_day=30
- goto final
- )
- if !tmp_last_month!==5 (
- set last_day=31
- goto final
- )
- if !tmp_last_month!==6 (
- set last_day=30
- goto final
- )
- if !tmp_last_month!==7 (
- set last_day=31
- goto final
- )
- if !tmp_last_month!==8 (
- set last_day=31
- goto final
- )
- if !tmp_last_month!==9 (
- set last_day=30
- goto final
- )
- if !tmp_last_month!==10 (
- set last_day=31
- goto final
- )
- if !tmp_last_month!==11 (
- set last_day=30
- goto final
- )
- ) else (goto :final)
-
- :leap_year
- set leapyear_flag=0
- set /a isleapyear=%curr_year%%%4
- if %isleapyear%==0 set leapyear_flag=1
- set /a isleapyear=%curr_year%%%400
- if %isleapyear%==0 set leapyear_flag=1
- set /a isleapyear=%curr_year%%%100
- if %isleapyear%==0 set leapyear_flag=0
- set tmp_last_day=28
- if %leapyear_flag%==1 set tmp_last_day=29
-
-
- :final
- if %tmp_last_month%==0 (
- set /a last_year=%curr_year%-1
- set last_month=12
- )
-
- set last_month=%temp_last_month%
- if %tmp_last_month%==1 set last_month=01
- if %tmp_last_month%==2 set last_month=02
- if %tmp_last_month%==3 set last_month=03
- if %tmp_last_month%==4 set last_month=04
- if %tmp_last_month%==5 set last_month=05
- if %tmp_last_month%==6 set last_month=06
- if %tmp_last_month%==7 set last_month=07
- if %tmp_last_month%==8 set last_month=08
- if %tmp_last_month%==9 set last_month=09
-
- set last_day=%tmp_last_day%
- if %tmp_last_day%==1 set last_day=01
- if %tmp_last_day%==2 set last_day=02
- if %tmp_last_day%==3 set last_day=03
- if %tmp_last_day%==4 set last_day=04
- if %tmp_last_day%==5 set last_day=05
- if %tmp_last_day%==6 set last_day=06
- if %tmp_last_day%==7 set last_day=07
- if %tmp_last_day%==8 set last_day=08
- if %tmp_last_day%==9 set last_day=09
-
- set dt=%last_year:~0,4%-%last_month:~0,2%-%last_day:~0,2%
-
- md d:\%dt%
复制代码
每次都执行到 leap_year, 帮忙看看是哪里的问题?
作者: Batcher 时间: 2013-9-3 08:33
参考
http://www.bathome.net/thread-3330-1-1.html
作者: zf0111_2000 时间: 2013-9-3 08:48
厉害,调用外部的函数库就这么简单。。。
作者: PowerShell 时间: 2013-9-3 09:39
假设今天是9月1日,那么下列代码就能返回8月31日,至于具体的日期形式,要靠 get-date -format xxx 参数控制。
powershell代码复制代码
作者: DAIC 时间: 2013-9-3 13:04
回复 4# PowerShell - (Get-Date -uformat "%Y-%m-%d").AddDays(-1)
复制代码
使用了format之后,get-date的结果就从日期时间对象编程普通字符串了,无法直接调用其AddDays方法,这个情况如何处理呢?
作者: PowerShell 时间: 2013-9-3 13:31
Get-Date (get-date).AddDays(-1) -uformat "%Y-%m-%d"
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |