---
# System prepended metadata

title: 取得時間
tags: [linux, script, windows]

---

# script 取得時間
###### tags: `script`, `windows`, `linux`

``` console=
@echo off
for /f "delims=" %%a in ('wmic os get LocalDateTime ^| find "."') do set datetime=%%a
set "year=%datetime:~0,4%"
set "month=%datetime:~4,2%"
set "day=%datetime:~6,2%"
set "hour=%datetime:~8,2%"
set "minute=%datetime:~10,2%"
echo %year%-%month%-%day%-%hour%:%minute%

```

``` bash
date +"%Y-%m-%d-%H:%M"
```