本帖最后由 77七 于 2023-8-19 19:23 编辑
a.txt- 19:33:30 August 16 2023> 企业 名称:优 美 利 A
- 19:35:30 August 16 2023> 企业 名称:优 美 利 A
- 19:36:30 August 16 2023> 企业 名称:优 美 利 A
- 19:37:30 August 16 2023> 企业 名称:优 美 利 A
- 19:38:31 August 16 2023> 退出
-
- 20:37:30 August 16 2023> 企业 名称:利海 B
- 20:38:31 August 16 2023> 退出
复制代码
- @echo off
- rem 批处理保存为ansi编码格式
- setlocal enabledelayedexpansion
- for %%a in (January February March April May June July August September October November December) do (
- set /a n+=1
- set %%a=!n!
- )
- (for /f "useback tokens=1-4*" %%a in ("a.txt") do (
- set str_year=%%d
- if "%%e" neq "退出 " (
- if not defined str_t1 (
- set str_t1=!str_year:~0,-1!-!%%b!-%%c %%a
- set str_name=%%e
- )
- ) else (
- set str_t2=!str_year:~0,-1!-!%%b!-%%c %%a
- call :t "!str_t1!" "!str_t2!" "!str_name!"
- set str_t1=
- set str_t2=
- )
- ))>b.txt
- endlocal
- pause
- exit
- :t
- ::日期时间差 code by foxjl
- set date1=%~1
- set date2=%~2
- for /f "tokens=1,2,3,4,5,6,7 delims=-/:. " %%i in ("%date1%") do ((set Y1=%%i) && (set M1=%%j) && (set D1=%%k) && (set H1=%%l) && (set F1=%%m) && (set S1=%%n) && (set MS1=%%o))
- for /f "tokens=1,2,3,4,5,6,7 delims=-/:. " %%i in ("%date2%") do ((set Y2=%%i) && (set M2=%%j) && (set D2=%%k) && (set H2=%%l) && (set F2=%%m) && (set S2=%%n) && (set MS2=%%o))
- set /a secs=((d2-32075+1461*(y2+4800+(m2-14)/12)/4+367*(m2-2-(m2-14)/12*12)/12-3*((y2+4900+(m2-14)/12)/100)/4)*86400+H2*3600+F2*60+S2)-((d1-32075+1461*(y1+4800+(m1-14)/12)/4+367*(m1-2-(m1-14)/12*12)/12-3*((y1+4900+(m1-14)/12)/100)/4)*86400+H1*3600+F1*60+S1)
- set /a D=secs/86400,H=(secs%%86400)/3600,M=(secs%%3600)/60,S=secs%%60
- set H=0%H%
- set M=0%M%
- set S=0%S%
- echo %~3 时间: %H:~-2%h:%M:~-2%m:%S:~-2%s
- exit /b
复制代码 时间的天数没有转换为小时,有点问题。 |