shifting time

W

winter

I was just wondering whether there is a *more elegant* way to adjust
the time by 1 minute using batch? I know I could use soon/rsoon (in
this case) but I wanted something portable.

@echo off
setlocal
time /t > %temp%\time
for /f "delims=: tokens=1,2" %%a in (%temp%\time) do (set t1=%%a &set
b=%%b)
echo %b% | find "PM" & if not errorlevel = 1 (set /a
t1="%t1:~0,2%+12") else (set /a t1=%t1:~0,2%)
set /a t2="%b:~0,2%+1"
::at "%t1%:%t2%" %1%

thx
 
P

Phil Robyn

winter said:
I was just wondering whether there is a *more elegant* way to adjust
the time by 1 minute using batch? I know I could use soon/rsoon (in
this case) but I wanted something portable.

@echo off
setlocal
time /t > %temp%\time
for /f "delims=: tokens=1,2" %%a in (%temp%\time) do (set t1=%%a &set
b=%%b)
echo %b% | find "PM" & if not errorlevel = 1 (set /a
t1="%t1:~0,2%+12") else (set /a t1=%t1:~0,2%)
set /a t2="%b:~0,2%+1"
::at "%t1%:%t2%" %1%

thx

What happens when you execute the preceding at 59 minutes past the hour?
 
M

Mark V

In said:
I was just wondering whether there is a *more elegant* way to
adjust the time by 1 minute using batch? I know I could use
soon/rsoon (in this case) but I wanted something portable.

@echo off
setlocal
time /t > %temp%\time
for /f "delims=: tokens=1,2" %%a in (%temp%\time) do (set t1=%%a
&set b=%%b)
echo %b% | find "PM" & if not errorlevel = 1 (set /a
t1="%t1:~0,2%+12") else (set /a t1=%t1:~0,2%)
set /a t2="%b:~0,2%+1"
::at "%t1%:%t2%" %1%

Off sideways...
The CMDTIME commandline utility can sync the local clock via NTP and
includes and "offset" switch (+mm) that can adjust the local clock to
be set mm minutes in advance ("fast") of the official time.
http://www.softshape.com/

Have no idea if this would be useful to your solution though.
 
G

Garry Deane

I was just wondering whether there is a *more elegant* way to adjust
the time by 1 minute using batch? I know I could use soon/rsoon (in
this case) but I wanted something portable.

@echo off
setlocal
time /t > %temp%\time
for /f "delims=: tokens=1,2" %%a in (%temp%\time) do (set t1=%%a &set
b=%%b)
echo %b% | find "PM" & if not errorlevel = 1 (set /a
t1="%t1:~0,2%+12") else (set /a t1=%t1:~0,2%)
set /a t2="%b:~0,2%+1"
::at "%t1%:%t2%" %1%

@echo off
setlocal
for /f "tokens=5-8 delims=:., " %%a in ('echo:^|time') do (
set hh=%%a&set /a mn=1%%b-99&set ss=%%c)
set /a mn%%=60
if %mn%==0 set /a hh+=1,hh%%=24
echo %hh%:%mn%:%ss%|time > nul

Garry
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top