Theme NexT works best with JavaScript enabled

ShunNien's Blog

不積跬步,無以致千里;不積小流,無以成江海。

0%

批次檔案取得檔的日期、時間欄位

Conetent

紀錄一下批次檔案取得日期與時間

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
@echo off

rem 取得今天日期的年、月、日三個欄位(透過 date /t 指令取得)
for /f "tokens=1-4 delims=-/ " %%i IN ('date /t') DO (
set year=%%i
set month=%%j
set day=%%k
set week=%%l
)

rem 取得當下時間的時、分兩個欄位
for /f "tokens=1-3 delims=:" %%i IN ('time /t') DO (
set hour=%%i
set minute=%%j
)

rem 濾掉 hour 前面可能會出現的空白以及上午下午的文字
for /f "tokens=1-2 delims= " %%i IN ("%hour%") DO (
set hour=%%j
)

echo "====== Start ======"
echo "date parameter = %date%"
echo "time parameter = %time%"
echo "year = %year%"
echo "month = %month%"
echo "day = %day%"
echo "week = %week%"
echo "minute = %minute%"
echo "hour = %hour%"
echo "====== End ======"
pause

Reference

歡迎關注我的其它發布渠道