本周批量日?

时间:2014-02-11 04:59:10

标签: html variables batch-file vbscript dayofweek

我想知道我是否可以通过某种批处理文件以某种方式弄清楚它是星期几(M,T,W,T,F,S& S)。如果它使用任何其他语言,只要最后,它设置为星期几的变量%DAY%就可以了。有没有办法实现这个目标?任何帮助将不胜感激!感谢。

2 个答案:

答案 0 :(得分:2)

您可以在批处理文件中将其丢弃。

@echo off  
set daysofweek=Mon,Tues,Wed,Thurs,Fri,Sat,Sun  
for /F "skip=2 tokens=2-4 delims=," %%A in ('WMIC Path Win32_LocalTime Get DayOfWeek /Format:csv') do set daynumber=%%A  
for /F "tokens=%daynumber% delims=," %%B in ("%daysofweek%") do set day=%%B
echo %day%

答案 1 :(得分:1)

由于没有wmic,因此没有Windows的家庭版本:

@echo off
setlocal
rem :: prints the day of the week
rem :: works on Vista and above
rem :: uses W32tm command

    rem :: getting ansi date ( days passed from 1st jan 1601 ) , timer server hour and current hour 
    FOR /F "skip=16 tokens=4,5 delims=:( " %%D in ('w32tm /stripchart /computer:localhost  /samples:1  /period:1 /dataonly /packetinfo') do (
     set "ANSI_DATE=%%D" 
     set  "TIMESERVER_HOURS=%%E" 
     goto :end_for  )
    :end_for
    set  "LOCAL_HOURS=%TIME:~0,2%"
    if "%TIMESERVER_HOURS:~0,1%0" EQU "00" set TIMESERVER_HOURS=%TIMESERVER_HOURS:~1,1%
    if "%LOCAL_HOURS:~0,1%0" EQU "00" set LOCAL_HOURS=%LOCAL_HOURS:~1,1%
    set /a OFFSET=TIMESERVER_HOURS-LOCAL_HOURS

    rem :: day of the week will be the modulus of 7 of local ansi date +1 
    rem :: we need need +1 because Monday will be calculated as 0
    rem ::  1st jan 1601 was Monday

    rem :: if abs(offset)>12 we are in different days with the time server

    IF %OFFSET%0 GTR 120 set /a DOW=(ANSI_DATE+1)%%7+1 
    IF %OFFSET%0 LSS -120 set /a DOW=(ANSI_DATE-1)%%7+1
    IF %OFFSET%0 LEQ 120 IF %OFFSET%0 GEQ -120 set /a DOW=ANSI_DATE%%7+1 


    echo Day of the week: %DOW%
    exit /b 2147483648
endlocal