2017-10-10 109 views
0

我想顯示給定日期的當天的名稱。我有一個代碼,可以從系統日期給我名字的一天。獲取當天的名字從日期起

@for /F "tokens=1 delims=, " %%i In ('powershell date') do set dow=%%i 
echo %dow% 

我怎樣才能顯示我將放入的任何日期的當天名稱? 我想要做這樣的事情(我已經設定的變量日,月和年之前):

@for /F "tokens=1 delims=, " %%i In ('powershell %day%/%month%/%year%') do set dow=%%i 
echo %dow% 
+1

這不是'bash',而是Powershell或M $批處理文件,我想。 – Alfe

+1

@Alfe我已將其編輯爲批處理文件 –

+0

https://stackoverflow.com/questions/11364147/setting-a-windows-batch-file-variable-to-the-day-of-the-week – Richard

回答

0

https://technet.microsoft.com/en-us/library/ff730960.aspx改編:

for /f "delims=" %%d in ('powershell (get-date %day%/%month%/%year%^).dayofweek') do set dow=%%d 

出於測試目的:

@echo off 
:... 
echo Command line: powershell (get-date %day%/%month%/%year%).dayofweek 
echo Result: 
powershell (get-date %day%/%month%/%year%).dayofweek 
for /f "delims=" %%d in ('powershell (get-date %day%/%month%/%year%^).dayofweek') do set dow=%%d 
echo dow=%dow% 
+0

@LS_DEV when ('powershell(get-date%day%/%month%/%year%^)。dayofweek')do set dow ='%% d' %% d''echo%dow%''它在命令提示符下給出了我:'ECHO is off'。我應該在運行程序之前在我的cmd上啓用了一些選項嗎? (昨天我試過的時候知道它工作的很好) –

+0

你在打電話之前是否定義過'year','month'和'day'? –

+0

使用'powershell測試輸出(get-date%day%/%month%/%year%)。dayofweek' –