本帖最后由 娜美 于 2023-9-12 19:28 编辑
回复 10# 77七 - @echo off
- chcp 65001 >nul
- rem 批处理保存为utf-8编码格式
- set /a m=n=2
- set /a "Jan=1,Feb=2,Mar=3,Apr=4,May=5,Jun=6,Jul=7,Aug=8,Sep=9,Oct=10,Nov=11,Dec=12"
- for /f "delims=" %%x in ('dir /b /a-d *.txt') do (
- setlocal enabledelayedexpansion
- for /f "useback tokens=1-9* delims=,. " %%a in ("%%x") do (
- if %%h equ 1 (
- set t1=%%d-!%%b!-%%c %%e
- set t2=%%f
- set ss1=%%j
- set s2=
- ) else if %%h equ 2 (
- if defined ss1 (
- set s2=1
- )
- ) else if %%h equ 3 (
- if defined s2 (
- call :1 "!t1!" "%%d-!%%b!-%%c %%e"
- if "%%f" geq "!t2!" (
- set /a m=n-1
- )
- if !secs! leq !m! (
- if "!ss1!" neq "%%j" (
- if not defined _"%%x" (
- >>out.txt echo %%x
- set _"%%x"=1
- )
- )
- )
- set ss1=
- set s2=
- )
- ) else (
- set ss1=
- set s2=
- )
- )
- endlocal
- )
- pause
- exit
-
- :1
- ::日期时间差 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)
- exit /b
复制代码 好奇怪, 时间计算似乎有些问题, 秒的单位如果0开头秒数, 导致时间计算条件失效, 其他数字开头的时间都准确, 唯独秒数 0开头不准确
例, 时间条件不符合,- 4 Jun 10, 2023 08:39:01.030724000 时间 1 4 6f89b2a23d4701b8eebabcf
- 6 Jun 10, 2023 08:39:05.898038000 时间 2 6 bb5c43db737f41
- 7 Jun 10, 2023 08:39:09.900620000 时间 3 7 6f89b2a23d4701b8eebabcf0
- 9 Jun 10, 2023 08:39:51.902646000 时间 9 9 1
复制代码 4 Jun 10, 2023 08:39:01.030724000 时间 1 4 6f89b2a23d4701b8eebabcf
6 Jun 10, 2023 08:39:05.898038000 时间 2 6 bb5c43db737f41
7 Jun 10, 2023 08:39:09.900620000 时间 3 7 6f89b2a23d4701b8eebabcf0
9 Jun 10, 2023 08:39:51.902646000 时间 9 9 1 |