2014-02-11 56 views
1

我想知道是否可以通過某種批處理文件找出每週的哪一天(M,T,W,T,F,S & S)。如果它使用任何其他語言,只要最後變量%DAY%設置爲一週中的某一天就可以。有沒有辦法做到這一點?任何幫助將不勝感激!謝謝。本週批次日?

+0

HTML? VBscript的?最好堅持使用最少數量的相關標籤。 –

+0

是的,我知道,但我在想有人知道其中一個人可能會有所幫助。 – drcomputer

+0

但是我的意思是,你可以用C,C++,Fortran,Java,程序集等編寫這個代碼。 –

回答

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% 
+0

非常感謝!作品!這需要管理員在XP?奇怪的。在學校在一些XP機器上運行全部7臺機器。你知道這件事嗎? – drcomputer

+0

這是通過WMI命令行使用WMI服務,因此它可能不在這些機器上運行? – QuickNull

1

由於WMIC不可用的窗口沒有回家版本:

@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 
+0

謝謝!我的學校實際上使用專業。 – drcomputer