本帖最后由 hnfeng 于 2024-3-5 17:40 编辑
初步可以了,但是因为想在 批处理面使用延迟变量,又不想 函数 里面的变量与从主代码里面的变量冲突,有没有办法呢?- @echo off&setlocal EnableDelayedExpansion&cd /d "%~dp0"&title %~nx0 &color 07
-
- call :Sec2Time 8 hhmmss
- echo 8 %hhmmss%
-
- call :Sec2Time 68 hhmmss
- echo 68 %hhmmss%
-
- call :Sec2Time 168 hhmmss
- echo 168 %hhmmss%
-
- call :Sec2Time 3668 hhmmss
- echo 3668 %hhmmss%
-
- call :Sec2Time 13668 hhmmss
- echo 13668 %hhmmss%
-
- call :Sec2Time 83668 hhmmss
- echo 83668 %hhmmss%
-
- echo;&pause
- exit /b
-
-
- ::==================================
- :Sec2Time
- set hh=00
- set mm=00
- set ss=00
- if %1 LSS 60 (
- set ss=0%1
- set %2=!hh!:!mm!:!ss:~-2!
- ) else (
- if %1 LSS 3600 (
- set /a mm=%1 / 60
- set /a ss=%1 - ^(!mm! * 60^)
- set mm=0!mm!
- set ss=0!ss!
- set %2=!hh!:!mm:~-2!:!ss:~-2!
- ) else (
- set /a hh=%1 / 3600
- set /a mm=^(%1 - ^(!hh! * 3600^)^) / 60
- set /a ss=%1 - !hh! * 3600 - !mm! * 60
- if !hh! LSS 10 set hh=0!hh!
- set mm=0!mm!
- set ss=0!ss!
- set %2=!hh!:!mm:~-2!:!ss:~-2!
- )
- )
- goto :EOF
复制代码
- 8 00:00:08
- 68 00:01:08
- 168 00:02:48
- 3668 01:01:08
- 13668 03:47:48
- 83668 23:14:28
-
- 请按任意键继续. . .
复制代码
|