~ Title bar Date & Clock help ~[ SOLVED ]

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Dos_Probie
Posts: 233
Joined: 21 Nov 2010 08:07
Location: At My Computer

~ Title bar Date & Clock help ~[ SOLVED ]

#1 Post by Dos_Probie » 29 Nov 2013 06:45

Got this below code that sets the current day, date and (fixed) time to the title bar,
would like to have the clock active where the minute would change and not be fixed once
the batch menu stays up, any ideas on a easy way to accomplish this? Thanks for the help..DP

Code: Select all

@echo off
:: Output day, date and time to title bar..
set daydate=%date%
for /f "tokens=1,2" %%a in ('time/t') do set time12=%%a %%b
title, %daydate% @ %time12%
:menu
:<Rest of menu with code>
pause
Last edited by Dos_Probie on 30 Nov 2013 19:12, edited 1 time in total.

einstein1969
Expert
Posts: 776
Joined: 15 Jun 2012 13:16
Location: Italy, Rome

Re: ~ Title bar Date & Clock help ~

#2 Post by einstein1969 » 29 Nov 2013 08:44

EDIT: Add auto-Sync to minute

Code: Select all

@echo off & setlocal EnableDelayedExpansion & goto :multithread_dispatcher

:Main 
  rem start timer sync to minute.
  start "" /B %0 timer_sync_to_minute set_title_date_time

:menu
  :<Rest of menu with code>
  pause
goto :eof


:: Functions/Subroutines ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

:set_title_date_time
  :: Output day, date and time to title bar..
  set daydate=%date%
  for /f "tokens=1,2" %%a in ('time/t') do set time12=%%a %%b
  title, %daydate% @ %time12%
goto :eof

:multithread_dispatcher
  if not "%1"=="" (
      set label=%1
      shift
      goto :!label!
  )
goto :Main

:timer_sync_to_minute %1=function-subroutine
  rem first time call function
  call :%1
:loop_timer_sync_to_minute
  :: calulate the distance to next minute.
  for /F "tokens=1-4 delims=:.," %%a in ("%time: =0%") do set /a "a=(6000-(1%%c%%d-10000))*10"
  rem echo %time% distance to next minute in ms:%a% & rem for debugging
  :: if now are in the first 30 seconds then call function
  if %a% gtr 30000 (call :%1) else title Syncing... & rem remove else part if don't want debug syncing work
  :: wait until next minute
  ping 192.0.2.0 -w %a% -n 1 >nul
goto :loop_timer_sync_to_minute



Einstein1969
Last edited by einstein1969 on 30 Nov 2013 09:12, edited 8 times in total.

Dos_Probie
Posts: 233
Joined: 21 Nov 2010 08:07
Location: At My Computer

Re: ~ Title bar Date & Clock help ~

#3 Post by Dos_Probie » 29 Nov 2013 14:00

Thanks for the Help Einstein! , the title clock lags about 20 sec behind the system clock (does not sync up) for some reason..DP

einstein1969
Expert
Posts: 776
Joined: 15 Jun 2012 13:16
Location: Italy, Rome

Re: ~ Title bar Date & Clock help ~

#4 Post by einstein1969 » 29 Nov 2013 15:20

Dos_Probie wrote:Thanks for the Help Einstein! , the title clock lags about 20 sec behind the system clock (does not sync up) for some reason..DP


because I not syncronize the timer with the clock.

can be solved with delayed start of the timer.

EDIT: I have edited the code of precedent post.

Einstein1969

Dos_Probie
Posts: 233
Joined: 21 Nov 2010 08:07
Location: At My Computer

Re: ~ Title bar Date & Clock help ~

#5 Post by Dos_Probie » 29 Nov 2013 16:22

Einstein, the 1st code you posted showed the date and time in title but now your updated code is not working at all now.. must be a typo somewhere.

AiroNG
Posts: 46
Joined: 17 Nov 2013 15:00
Location: Germany

Re: ~ Title bar Date & Clock help ~

#6 Post by AiroNG » 29 Nov 2013 17:00

Dos_Probie wrote:Einstein, the 1st code you posted showed the date and time in title but now your updated code is not working at all now.. must be a typo somewhere.


I just tried the posted code and it works. Just wait a few seconds.

einstein1969
Expert
Posts: 776
Joined: 15 Jun 2012 13:16
Location: Italy, Rome

Re: ~ Title bar Date & Clock help ~

#7 Post by einstein1969 » 29 Nov 2013 17:04

it works for me. :?

I have changed the set, try it now.

However, it takes up to a minute to display the first time because it has a delayed start. If you want see immediatly must add a call to the function.


Code: Select all

:Main
  rem calulate the delay (in seconds) for sync to minute.
  set /a "msec=(60-(1!time:~6,2!-100))*1000"

  rem start the timer delayed
  start "" /B %0 timer_delayed %msec% set_title_date_time 60000

  call :set_title_date_time

:menu
  :<Rest of menu with code>
  pause
goto :eof

einstein1969
Expert
Posts: 776
Joined: 15 Jun 2012 13:16
Location: Italy, Rome

Re: ~ Title bar Date & Clock help ~

#8 Post by einstein1969 » 29 Nov 2013 17:09

AiroNG wrote:
Dos_Probie wrote:Einstein, the 1st code you posted showed the date and time in title but now your updated code is not working at all now.. must be a typo somewhere.


I just tried the posted code and it works. Just wait a few seconds.


thanks for trying. However, I corrected the "set msec ..." because he had no double quotes. and have added e delayed time variable.

einstein1969

AiroNG
Posts: 46
Joined: 17 Nov 2013 15:00
Location: Germany

Re: ~ Title bar Date & Clock help ~

#9 Post by AiroNG » 29 Nov 2013 17:16

thanks for trying. However, I corrected the "set msec ..." because he had no double quotes. and have added e delayed time variable.

Then i must have used the already edited code right before you answered.

Apologies Dos_Probie. My timing was bad.

einstein1969
Expert
Posts: 776
Joined: 15 Jun 2012 13:16
Location: Italy, Rome

Re: ~ Title bar Date & Clock help ~

#10 Post by einstein1969 » 29 Nov 2013 17:21

there is another problem. Now lag is one minute! :roll:

einstein1969
Expert
Posts: 776
Joined: 15 Jun 2012 13:16
Location: Italy, Rome

Re: ~ Title bar Date & Clock help ~

#11 Post by einstein1969 » 29 Nov 2013 17:31

I have added 2 second at the delayed start. One because of round error of hundredth of second and another for safety.

Code: Select all

  set /a "msec=(60-(1!time:~6,2!-100)+2)*1000"


I suppose it serves a function resynchronization timer ... :?

Einstein1969

Dos_Probie
Posts: 233
Joined: 21 Nov 2010 08:07
Location: At My Computer

Re: ~ Title bar Date & Clock help ~

#12 Post by Dos_Probie » 29 Nov 2013 20:10

I reloaded your code and gives the path to my batch in title, until the min change then starts working..Will play around with it, just was hoping to get it to snyc right away like the post from Carlos and Aacini at: viewtopic.php?f=3&t=5028

einstein1969
Expert
Posts: 776
Joined: 15 Jun 2012 13:16
Location: Italy, Rome

Re: ~ Title bar Date & Clock help ~

#13 Post by einstein1969 » 30 Nov 2013 09:04

I have add auto resync to minute. Now is more precise and light. Try!

Einstein1969

Dos_Probie
Posts: 233
Joined: 21 Nov 2010 08:07
Location: At My Computer

Re: ~ Title bar Date & Clock help ~

#14 Post by Dos_Probie » 30 Nov 2013 19:12

The auto sync did the trick, Thanks for all your Help, much appreciated!..DP :wink:

Post Reply