• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Milliseconds to "formatted time"
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Milliseconds to "formatted time"


  • Subject: Re: Milliseconds to "formatted time"
  • From: "Nigel Garvey" <email@hidden>
  • Date: Sat, 16 Jul 2005 13:00:55 +0100

jj wrote on Sat, 16 Jul 2005 10:15:36 +0200:

>> Before re-inventing the wheel, there is a quick (or fast) and vanilla
>> solution to convert milliseconds to a formatted time string? Eg:
>
>Well, here is a sample supporting 24-hours formatting:
>
>millisecToFormattedTime(4806790) --> "01:20:06.790"
>
>to millisecToFormattedTime(tMs)
>    set finalHours to tMs div 3600000
>    set remMS to tMs mod 3600000
>
>    set finalMins to remMS div 60000
>    set remMS to remMS mod 60000
>
>    set finalSecs to remMS div 1000
>    set remMS to remMS mod 1000
>
>    return "" & (text -2 thru -1 of ("00" & finalHours)) & ":" & (text -2
>thru -1 of ("00" & finalMins)) & ":" & (text -2 thru -1 of ("00" &
>finalSecs)) & "." & (text -3 thru -1 of ("00" & remMS))
>end millisecToFormattedTime

100-hour formatting, actually. :-) Here's a faster version:

  millisecToFormattedTime(4806790) --> "01:20:06.790"

  to millisecToFormattedTime(ms)
    set ms to ms div 1 -- in case it's a real
    tell (10000000 + ms div 60000 mod 60 * 100000 + ms mod 100000) as string
      return text 2 thru 3 of ((100 + ms div 3600000) as string) & ":" &
text 2 thru 3 & ":" & text 4 thru 5 & "." & text 6 thru 8
    end tell
  end millisecToFormattedTime


NG

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Prev by Date: Re: what happened to Mail's scripts menu?
  • Next by Date: Re: what happened to Mail's scripts menu?
  • Previous by thread: Re: Milliseconds to "formatted time"
  • Next by thread: Application-specific code in handler won't execute
  • Index(es):
    • Date
    • Thread