我需要向批处理文件发送日期并让它返回星期几。日期参数可以是过去或将来。我查看了许多日期函数,但它们都使用了今天的日期。是否可以通过向批处理文件发送日期参数来返回星期几?我使用的是Windows 7.
答案 0 :(得分:2)
在Powershell的帮助下:
set a=03.12.2013
for /f %%i in ('powershell ^(Get-Date %a% -f dddd^)') do set long=%%i
for /f %%i in ('powershell ^(Get-Date %a% -f ddd^)') do set short=%%i
echo Day is %long% (%short%)
答案 1 :(得分:1)
将其保存为.bat
并将date1
更改为您想要的日期
@if (@X)==(@Y) @end/*** Javascript comment
@echo off
set "date1=04/14/2014"
(
mshta "about:<title>dow</title><body onload='init("%date1%")'><script language='javascript' src='file://%~dpnxf0'></script><span id='arg1'>%date1%</span></body>"
) | (
for /f "tokens=* delims=" %%B in ('more') do (
echo day of the week: %%B
)
)
exit /b 0
**/
function init(ds) {
//var dt = document.getElementById('arg1').value;
var the_date=new Date(Date.parse(ds));
var the_day=the_date.getDay();
//alert(the_day);
var fso= new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1);
//fso.Write(the_date.getDay());
close(fso.Write(the_day));
}
答案 2 :(得分:1)
这是一个使用VBS获取工作日的批处理脚本。
:: Get weekday and day of week number, for a date
@echo off
if "%~1"=="" echo Use this to get the day of week: "%~nx0" dd-mm-yyyy& pause & goto :EOF
set file="%temp%\%~n0.temp.vbs"
echo>%file% WScript.Echo weekday(#%~1#)
for /f %%a in ('cscript //nologo %file%') do set "daynum=%%a"
del %file%
for /f "tokens=%daynum% delims=," %%a in ("Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday") do set "weekday=%%a"
echo dow is "%daynum%" - "%weekday%"
pause