中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-10-24 06:34
47,815 topics / 349,928 posts / today 1 new / 48,287 members
DOS批处理 & 脚本技术(批处理室) » Batch script to convert seconds into days, hours, minutes and seconds
Printable Version  5,844 / 24
Floor16 zouzhxi Posted 2007-01-17 09:52
中级用户 Posts 177 Credits 430 From 广东深圳
If I enter a letter, it still appears:


Please enter the number of seconds: dddd

0 days 0 hours 0 minutes 0 seconds

Press any key to continue...


Am I here to cause trouble,,, hehehe... ;)

[ Last edited by zouzhxi on 2007-1-17 at 09:54 AM ]
Floor17 PPdos Posted 2007-01-17 11:02
高级用户 Posts 268 Credits 783
Understand the above code as (not milliseconds):

set /a D=%t%/86400
set /a H=%t%%%86400/3600
set /a M=%t%%%86400%%3600/60
set /a S=%t%%%86400%%3600%%60
ECHO %D% days %H% hours %M% minutes %S% seconds

The perception is: The value is t divided by 86400 seconds (equal to 1 day), the quotient is the number of days, the remainder is divided by 3600 seconds (equal to 1 hour), the quotient is the number of hours, and the remainder is cycled again, and so on, which can be extended to weeks, months, and years. But due to the 32-bit precision limit, it will not achieve the maximum expected effect
Floor18 hxuan999 Posted 2007-01-18 01:55
中级用户 Posts 161 Credits 337
Originally posted by namejm at 2007-1-16 16:15:
  The code on floor 12 has the following defects:

  1. Using a replace statement to intercept the decimal part is error-prone. For example, when the integer part is a certain string of the decimal part, such as 23.1234. It is recommended not ...


Thanks for pointing it out, hehe. It was written carelessly. It has been corrected.
Floor19 everest79 Posted 2007-01-18 07:15
金牌会员 Posts 1,127 Credits 2,564
Originally posted by PPdos at 2007-1-16 08:39 PM:
You guys are amazing. You even got the milliseconds accurate. It seems it can be modified into a Spring Festival countdown^^



I just wrote this hehe :D
Floor20 uiopuiop Posted 2007-10-05 10:21
中级用户 Posts 211 Credits 400
Is there a way to break through the 11-day limit? If the number is too large, it will overflow. Thanks!

Please enter the number of seconds (press Enter directly to exit): 4321432531252
Invalid number. Numbers are limited to 32-bits of precision.
Invalid number. Numbers are limited to 32-bits of precision.
Invalid number. Numbers are limited to 32-bits of precision.
Invalid number. Numbers are limited to 32-bits of precision.

11 days 32 hours 19 minutes 47 seconds
Floor21 uiopuiop Posted 2007-10-05 10:27
中级用户 Posts 211 Credits 400
This forum is really good!!! Strongly support!

@echo off
:begin
cls
echo.
set input=
set /p input= Please enter the number of seconds (press Enter directly to exit):
if not defined input exit
set /a SS=%input%%%60
set /a MM=%input%/60%%60
set /a HH=%input%/3600%%60
if %HH% GEQ 24 set /a HH=HH%%24
set /a DD=%input%/86400
if %DD% GEQ 7 set /a DD=DD%%7
set /a WW=%input%/604800%%60
echo.
if %DD% GEQ 1 (echo %WW% weeks %DD% days %HH% hours %MM% minutes %SS% seconds
) else (
echo %DD% days %HH% hours %MM% minutes %SS% seconds
)
echo.
pause
goto begin

[ Last edited by uiopuiop on 2007-10-5 at 11:28 AM ]
Floor22 uiopuiop Posted 2007-10-05 10:33
中级用户 Posts 211 Credits 400
However...

Please enter the number of seconds (press Enter directly to exit): 65356534654
Invalid number. Numbers are limited to 32-bits of precision.
Invalid number. Numbers are limited to 32-bits of precision.
Invalid number. Numbers are limited to 32-bits of precision.
Invalid number. Numbers are limited to 32-bits of precision.
Invalid number. Numbers are limited to 32-bits of precision.

29 weeks 25 days 10 hours 33 minutes 20 seconds
Floor23 uiopuiop Posted 2007-10-05 11:53
中级用户 Posts 211 Credits 400
Please enter the number of seconds (press Enter directly to exit): 3431253

5 weeks 4 days 5 hours 7 minutes 33 seconds

It seems it should be 17 hours, not 5 hours...

[ Last edited by uiopuiop on 2007-10-5 at 12:04 PM ]
Floor24 scriptor Posted 2007-10-05 12:25
银牌会员 Posts 555 Credits 1,187
Floor25 uiopuiop Posted 2007-10-05 12:29
中级用户 Posts 211 Credits 400
Your algorithm is very good, I am stupid. How to input a number in seconds and output it with precision to seconds only. And the code is in a batch file.

Can you write it out, thank you very much!

[ Last edited by uiopuiop on 2007-10-5 at 12:54 PM ]
Prev  1 2
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023