Leading zeros for time string

Is there a way to add a leading zeros to “time string”

ex.

set currentTime to time string of (current date)

If it is 3am, 7 minutes after, and 6 seconds the above command returns 3:7:6.
What I would like is 03:07:06.

I figured out how to do this for dates, just having a time (pun intended) with time.

Hi, donnyl.

‘time string’ returns the time in the format set in the user’s Date and Time settings. (System Preferences → Language & Text → Formats → Times.) The result therefore depends on the user’s preference for leading zeros or not and whether he/she uses a 12-hour or 24-hour clock.

If you want to impose a format, it’s easiest to get the ‘time’ of the date and create your own string from it. (Actually, it’s slightly easier to use the date’s ‘hours’, ‘minutes’, and ‘seconds’, but I don’t like them. :wink: )

set t to time of (current date)
tell (1000000 + (t div hours) * 10000 + (t mod hours div minutes) * 100 + t mod minutes) as text to ¬
	set timeString to text 2 thru 3 & ":" & text 4 thru 5 & ":" & text 6 thru 7

By the way, your query should have been posted on the OS X forum. Code Exchange is for sharing code that you’ve already written.