Max Script to create a digital clock

Hi
I am trying to create a script with timer for UI and with labels in the max. What i want to do is to stop the timer and 60 for seconds and update 1 for minutes. That part is done but can;t actually stop the seconds at 60 and restart the counter again. And I dont want to use another timer for the minutes as i am doing now but the seconds should affect the counter of the number of the minutes. Here is the code for it:

Rollout DigiClock “Digital Clock”
(
local sec,
min

timer SecTme "Tme" interval:1000
timer MinTme "MinTme" interval: 60000
label hour " Hr     Mn    Sc" align:#left
label dots " :        :" across: 20 offset: [30,0] align:#center
label hrs "00" across:30 align:#center 
label minuts "00" offset:[20,0]
label secs "01" offset:[40,0]
    
fn SecTime = 
(
    sec =(secs.text as integer)+1
    if sec <10 then
    (
        secs.text = "0" +sec as string
        ) else
    (
        secs.text = sec as string
        )
    )
    
fn MinTime = 
(
    min =(minuts.text as integer)+1
    if min <10 then
    (
        minuts.text = "0" +min as string
        ) else
    (
        minuts.text = min as string
        )
    )

On SecTme tick do
(
    SecTime()
    )
On MinTme tick do
(
    MinTime()
    )

)

createDialog DigiClock width:150

Why not simply format a string into a single label from seconds alone?
Like this:


Rollout DigiClock "DigiClock"
(
	local tsec = 0
	
	timer SecTme "Tme" interval:1000 
	label l_time "00 : 00 : 00" align:#center

	On SecTme tick do
	(
		tsec += 1
		
		local h = tsec/3600
		local sh = if h < 10 then "0"+h as string
					else h as string
		local m = (mod (tsec/60) 60) as integer
		local sm = if m < 10 then "0"+m as string
					else m as string
		local s = (mod tsec 60) as integer
		local ss = if s < 10 then "0"+s as string
					else s as string

		l_time.text = sh+" : "+sm+" : "+ss
	)
)
createDialog DigiClock width:90 height:26

Wow… thanks a lot. I tried some thing like this initially but dint know the mod stuff as i am kinda new to max script. Thanks a bunch once again

You can also use .NET to make it more maintainable, for a different time format simply replace the formatStr contents with something more fitting:

try destroyDialog DigiClock catch()
rollout DigiClock "DigiClock"
(
	local timeSpan = dotNetClass "TimeSpan"
	local formatStr = "hh' : 'mm' : 'ss"

	timer clock interval:1000
	label l_time "00 : 00 : 00" align:#center

	on clock tick do l_time.text = (timeSpan.FromSeconds clock.ticks).ToString formatStr
)
createDialog DigiClock width:90 height:26