0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Windowsバッチファイルで現在日時を出力する方法

Last updated at Posted at 2022-11-19

1. はじめに

今回は、自分自身への備忘録を兼ねて、Windowsバッチファイルで現在日時を出力する方法を、お伝えしたいと思います

2. この記事を読んでできること

  • Windowsバッチファイルで現在日時を出力できるようになる

3. 注意事項

4. 必要なもの

  • Windows OS PC(Windows11を想定)
  • テキストエディタ

5. 現在日時出力バッチファイル

  • .batファイルを作成し、実行する
timestamp.bat
@echo off
cd /d %~dp0
setlocal enabledelayedexpansion

rem 現在日時を取得
set YYYY=%Date:~0,4%
set MM=%Date:~5,2%
set DD=%Date:~8,2%

set HH=%Time:~0,2%
set HH=%HH: =0%

set MIN=%Time:~3,2%
set MIN=%MIN: =0%

set SS=%Time:~6,2%
set SS=%SS: =0%

set TIMESTAMP=%YYYY%%MM%%DD%%HH%%MIN%%SS%

rem 現在日時を出力
echo %TIMESTAMP%

endlocal
pause
exit /b

6. おわりに

いかがでしたでしょうか?Windowsバッチファイルで現在日時を出力することができたのではないかと思います
今回の記事が、みなさまの学習の参考になれば幸いです

2022/11/19 TAKAHIRO NISHIZONO


0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?