Files
Obsidian-Main/-21.02. Windows/command.md

15 lines
458 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
### 取得日期時間
在 batch 檔裡面可以用 `%date%``%time%` 來取得日期時間。
`%date:~0,4%` 來擷取特定欄位。
`~0,4` 表示**從 index 0 開始取 4 位**,所以假設原本 `%date%` 會輸出 `2024/05/29` `%date:~0,4%` 則會輸出 `2024`
取得年、月、日、時、分、秒下:
```bat
set YYYY=%date:~0,4%
set MM=%date:~5,2%
set DD=%date:~8,2%
set HOUR=%time:~0,2%
set MIN=%time:~3,2%
set SEC=%time:~6,2%
```