Getting time (milliseconds) in LCB

LiveCode Builder is a language for extending LiveCode's capabilities, creating new object types as Widgets, and libraries that access lower-level APIs in OSes, applications, and DLLs.

Moderators: LCMark, LCfraser

Post Reply
pklum
Posts: 30
Joined: Fri Jan 17, 2025 6:47 pm
Contact:

Getting time (milliseconds) in LCB

Post by pklum »

Hi,
I have tried to get the milliseconds in LCB, but failed every atempt.
How do I get milliseconds or seconds in the best way?

Best Regards
Peter
Emily-Elizabeth
Posts: 239
Joined: Mon Jan 03, 2022 7:10 pm
Contact:

Re: Getting time (milliseconds) in LCB

Post by Emily-Elizabeth »

You'd have to do some math, but looks like there is a function to get the seconds from the epoch

https://docs.livecode.com/docs/LiveCode ... versalTime
victoriasmith
Posts: 2
Joined: Sun Nov 08, 2026 10:06 am

Re: Getting time (milliseconds) in LCB

Post by victoriasmith »

Peter, the epoch-seconds function is the practical starting point. Multiply the returned seconds by 1000 for milliseconds; for higher precision you'll need to combine it with a sub-second timer and do the arithmetic yourself, since the function alone won't give fractional milliseconds. Keep the multiplication explicit so it's clear where the conversion happens. If you only need elapsed time rather than a wall-clock timestamp, a timer is usually a simpler and more reliable choice than working from epoch values.
pklum
Posts: 30
Joined: Fri Jan 17, 2025 6:47 pm
Contact:

Re: Getting time (milliseconds) in LCB

Post by pklum »

Hi,
Thank you!
Will look into your recommendation.

Regards,
Peter
PaulDaMacMan
Posts: 697
Joined: Wed Apr 24, 2013 4:53 pm
Contact:

Re: Getting time (milliseconds) in LCB

Post by PaulDaMacMan »

Microseconds, more precise but if you need milliseconds you could always get 'the millseconds' by evaluating script from LCB:

Code: Select all

execute script "return the milliseconds"
Then coerce to an a numeric type if you need to.

Code: Select all

variable tNum as optional Number
execute script "return the milliseconds"
put the result parsed as number into tNum
Note: An error is thrown if this syntax is used in a context where access to script objects is not allowed.
Best 'trick', out of many, that I picked up from the great Herman Hoch (R.I.P.)
Although using 'the universal time' and then doing the math would probably be faster for this.
My GitHub Repos: https://github.com/PaulMcClernan/
Related YouTube Videos: PlayList
Post Reply