本帖最后由 likeyou32 于 2024-3-13 09:12 编辑
- @echo off
- setlocal enabledelayedexpansion
- for /f "tokens=1,2 delims=:" %%i in ('time/t') do (
- set xian=%%i%%j & set xianshi=%%i & set xianfen=%%j
- for /f "skip=1 tokens=10,11 delims=-: " %%a in ('query user') do (
- set chu=%%a%%b & set chushi=%%a & set chufen=%%b
- )
- )
- rem endlocal
- set /a xianshi=1%xianshi%-100,xianfen=1%xianfen%-100
- for /f "skip=1 tokens=6,7,8 delims=- " %%u in ('query user') do (
- for /f "tokens=1,2,3 delims=- " %%r in ('date/t') do (
- SET DateA=%%u%%v%%w & set DateB=%%r%%s%%t
- echo !DateA! !dateb!
- )
- )
- call :DateToDays %DateA:~0,4% %DateA:~4,2% %DateA:~6,2% DaysX
- call :DateToDays %DateB:~0,4% %DateB:~4,2% %DateB:~6,2% DaysY
- if %DaysX% geq %DaysY% (set /a DayZ=DaysX-DaysY) else (set /a DayZ=DaysY-DaysX)
- echo %DateA%和%DateB%间隔的天数是:%DayZ%天
- if %xianshi% geq %chushi% (if %xianfen% geq %chufen% set /a fen=%xianfen%-%chufen% & set /a shi=%xianshi%-%chushi% )else (
- if %xianfen% geq %chufen% (set /a fen=xianfen-chufen,shi=24-chushi+xianshi-24) else (set /a fen=60+xianfen-chufen,shi=24-chushi+xianshi-24-1)
- )
- set /a zongshi=DayZ*24+shi
- echo 合计%zongshi%小时%fen%分钟
- goto :eof
-
- :DateToDays %yy% %mm% %dd% days
- setlocal ENABLEEXTENSIONS
- set yy=%1&set mm=%2&set dd=%3
- if 1%yy% LSS 200 if 1%yy% LSS 170 (set yy=20%yy%) else (set yy=19%yy%)
- set /a dd=100%dd%%%100,mm=100%mm%%%100
- set /a z=14-mm,z/=12,y=yy+4800-z,m=mm+12*z-3,j=153*m+2
- set /a j=j/5+dd+y*365+y/4-y/100+y/400-2472633
- endlocal&set %4=%j%&goto :EOF
复制代码 请大家指教 |