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?

指定した時間にそれぞれ表示する

Posted at

指定した時間にメッセージを表示する

@echo off
setlocal enabledelayedexpansion

:: 現在時刻を取得
set "NOW=%TIME%"

:: 時と分を取り出して数値化(先頭スペース対策付き)
set "HOUR=%NOW:~0,2%"
set "MIN=%NOW:~3,2%"
set /a HOUR=1%HOUR% - 100
set /a MIN=1%MIN% - 100

:: 現在時刻を分単位に変換(例:10:30 → 630)
set /a NOW_MINUTES=HOUR*60+MIN

:: 各時間帯を分単位で定義
set /a WORK_START=10*60
set /a LUNCH_START=12*60
set /a LUNCH_END=13*60
set /a WORK_END=18*60

:: メッセージ分岐
if !NOW_MINUTES! GEQ !LUNCH_START! if !NOW_MINUTES! LSS !LUNCH_END! (
    echo  Bです(12:00~13:00)
) else if !NOW_MINUTES! GEQ !WORK_START! if !NOW_MINUTES! LSS !WORK_END! (
    echo  Aです(10:00~18:00)
) else (
    echo  Cです
)

endlocal
pause
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?