transform seconds in hours, minutes and seconds

Hi,

i want to transform seconds in three categories, how already says the title.
if i calc (as example) 270/60 i got 4.5, but i want an exact result, with seconds.
270/minutes as integer isnt what i want.

I wrote this a month ago, there might be an AS way though:

on subcalctime(valtime)
	set valhrs to subaddzero(round valtime / 60 / 60 rounding down)
	set valmin to subaddzero(round (valtime - valhrs * 60 * 60) / 60 rounding down)
	set valsec to subaddzero((valtime - valhrs * 60 * 60) - (valmin * 60))
	return valhrs & ":" & valmin & ":" & valsec as string
end subcalctime

on subaddzero(valnum)
	return text -2 thru -1 of ("0" & valnum)
end subaddzero

i suspected that the processing wasn’t so easy to solve. Your snipped is more than enough man, and thanks!
A good cristmas time.

Hi,

I’m using this one


set timeString to hrMnSc(270)

on hrMnSc(secs)
	tell secs to set {hr, mn, sc} to {it div hours, it mod hours div minutes, it mod hours mod minutes div 1}
	return padZero(hr) & ":" & padZero(mn) & ":" & padZero(sc)
end hrMnSc

on padZero(v)
	return text -2 thru -1 of ("0" & v)
end padZero

Hi, guys.
thanks to both- i wrote a nice and very handy applescript, using the routine of Richard (thanks) to read easier the results of time.
The idea behind my script is to control your personal time plan; a second step will be to import the generated text file in Numbers or Excel to view some diagrams- the creation date of the text file itself gives information about the date of your working period.
For now i’m unable to work on the second step, (i’ never wrote a script for Numbers) but i’m nevertheless happy.
I hope you will celebrate a nice cristmas, without stress, so use this script with caution!
;D

here’s the script:

--Working plan
--System
--ideal zum exportieren für MS Excel, Numbers, ecc..
--Datumangabe mittels dem Herstellungssatum der TextDatei selbst

set Zeit1 to current date
set {Htag, Hmon, HJahr} to {(day of Zeit1), (month of Zeit1 as number), (characters 3 thru 4 of (year of Zeit1 as text) as text)}
set DatumAngabe to (Htag & "-" & Hmon & "-" & HJahr) as text

set rep_pf to POSIX path of ((path to desktop) & "Working plan" & space & DatumAngabe & ".txt" as text)
set rep_pf to POSIX file rep_pf
set Anfangs_akt to {(hours of Zeit1) & ":" & (minutes of Zeit1) & ":" & (seconds of Zeit1)}


-----------------------------------------------------------------------------------
with timeout of 43200 seconds
	activate me
	display dialog "Twelve hours (720 min.) as limit" buttons "Stop Tracker" with icon 1
	set Zeit2 to current date
	set z_unters to Zeit2 - Zeit1
	
	set die_Z to my subcalctime(z_unters)
	
	-----------------------------------------------------------------------------------
	set Ende_akt to {((hours of Zeit2) & ":" & (minutes of Zeit2) & ":" & (seconds of Zeit2))}
	
	set arbeitszeit to display dialog "elapsed time is " & die_Z & return & "confirm to see your time expense." buttons {"Report", "Cancel"}
	if button returned of arbeitszeit = "Report" then
		set arbeits_ls to {"Cad", "Concept", "Mails", "_________", "Organize", "Collect data", "Research", "_________", "Read", "Learn", "Languages", "Typetrainer", "Applescript"}
		set Beschreib to choose from list arbeits_ls
		set Beschreib_a to the result as text
	else
		return 0
	end if
	
	-----------------------------------------------------------------------------------
	set Eintrag to Beschreib_a & tab & die_Z & tab & Anfangs_akt & tab & Ende_akt & return
	
	try
		set rep_dt to open for access rep_pf with write permission
		write Eintrag to rep_dt starting at (get eof rep_dt) + 1
		close access rep_dt
	on error
		display dialog "Unable to add the new working report to the existing plan." with icon 0 giving up after 10
	end try
end timeout

on subcalctime(z_unters)
	set valhrs to subaddzero(round z_unters / 60 / 60 rounding down)
	set valmin to subaddzero(round (z_unters - valhrs * 60 * 60) / 60 rounding down)
	set valsec to subaddzero((z_unters - valhrs * 60 * 60) - (valmin * 60))
	return valhrs & ":" & valmin & ":" & valsec as string
end subcalctime

on subaddzero(valnum)
	return text -2 thru -1 of ("0" & valnum)
end subaddzero

Nice script. :slight_smile:

Little note: The timeout block is completely useless. Timeout blocks affect only Apple Events sent and received by applications. Standard Additions (and also shell scripts) don’t send Apple Events

ops…